public function AssetInjectorFormBase::form in Asset Injector 8.2
Same name and namespace in other branches
- 8 src/Form/AssetInjectorFormBase.php \Drupal\asset_injector\Form\AssetInjectorFormBase::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
2 calls to AssetInjectorFormBase::form()
- AssetInjectorCssForm::form in src/
Form/ AssetInjectorCssForm.php - Gets the actual form array to be built.
- AssetInjectorJsForm::form in src/
Form/ AssetInjectorJsForm.php - Gets the actual form array to be built.
2 methods override AssetInjectorFormBase::form()
- AssetInjectorCssForm::form in src/
Form/ AssetInjectorCssForm.php - Gets the actual form array to be built.
- AssetInjectorJsForm::form in src/
Form/ AssetInjectorJsForm.php - Gets the actual form array to be built.
File
- src/
Form/ AssetInjectorFormBase.php, line 121
Class
- AssetInjectorFormBase
- Class AssetInjectorCsssForm.
Namespace
Drupal\asset_injector\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['#tree'] = TRUE;
// Store the gathered contexts in the form state for other objects to use
// during form building.
$form_state
->setTemporaryValue('gathered_contexts', $this->contextRepository
->getAvailableContexts());
/** @var \Drupal\asset_injector\Entity\AssetInjectorBase $entity */
$entity = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $entity
->label(),
'#description' => $this
->t('Label for the @type.', [
'@type' => $entity
->getEntityType()
->getLabel(),
]),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $entity
->id(),
'#machine_name' => [
'exists' => '\\' . $entity
->getEntityType()
->getClass() . '::load',
'replace_pattern' => '[^a-z0-9_]+',
'replace' => '_',
],
'#disabled' => !$entity
->isNew(),
];
$form['code'] = [
'#type' => 'textarea',
'#title' => $this
->t('Code'),
'#description' => $this
->t('The actual code goes in here.'),
'#rows' => 10,
'#default_value' => $entity->code,
'#required' => TRUE,
'#prefix' => '<div>',
'#suffix' => '<div class="resizable"><div class="ace-editor"></div></div></div>',
];
$form['conditions'] = $this
->buildConditionsInterface([], $form_state);
$form['conditions']['#weight'] = 99;
$form['conditions_and_or'] = [
'#type' => 'details',
'#title' => $this
->t('Condition Requirements'),
'#group' => 'conditions_tabs',
'#weight' => 999,
'#tree' => FALSE,
];
$form['conditions_and_or']['conditions_require_all'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Require all conditions'),
'#description' => $this
->t('Check to require all conditions. Leave uncheck to require any condition.'),
'#default_value' => $entity->conditions_require_all,
];
$form['#attached']['library'][] = 'asset_injector/ace-editor';
return $form;
}