public function FieldFormBase::buildForm in Display Suite 8.2
Same name and namespace in other branches
- 8.4 src/Form/FieldFormBase.php \Drupal\ds\Form\FieldFormBase::buildForm()
- 8.3 src/Form/FieldFormBase.php \Drupal\ds\Form\FieldFormBase::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
3 calls to FieldFormBase::buildForm()
- BlockFieldForm::buildForm in src/
Form/ BlockFieldForm.php - Form constructor.
- CopyFieldForm::buildForm in src/
Form/ CopyFieldForm.php - Form constructor.
- TokenFieldForm::buildForm in src/
Form/ TokenFieldForm.php - Form constructor.
4 methods override FieldFormBase::buildForm()
- BlockFieldConfigForm::buildForm in src/
Form/ BlockFieldConfigForm.php - Form constructor.
- BlockFieldForm::buildForm in src/
Form/ BlockFieldForm.php - Form constructor.
- CopyFieldForm::buildForm in src/
Form/ CopyFieldForm.php - Form constructor.
- TokenFieldForm::buildForm in src/
Form/ TokenFieldForm.php - Form constructor.
File
- src/
Form/ FieldFormBase.php, line 90
Class
- FieldFormBase
- Base form for fields.
Namespace
Drupal\ds\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') {
// Initialize field.
$field = array();
// Fetch field if it already exists.
if (!empty($field_key)) {
$field = $this
->config('ds.field.' . $field_key)
->get();
}
// Save the field for future reuse.
$this->field = $field;
$form['name'] = array(
'#title' => $this
->t('Label'),
'#type' => 'textfield',
'#default_value' => isset($field['label']) ? $field['label'] : '',
'#description' => $this
->t('The human-readable label of the field.'),
'#maxlength' => 128,
'#required' => TRUE,
'#size' => 30,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => isset($field['id']) ? $field['id'] : '',
'#maxlength' => 32,
'#description' => $this
->t('The machine-readable name of this field. This name must contain only lowercase letters and underscores. This name must be unique.'),
'#disabled' => !empty($field['id']),
'#machine_name' => array(
'exists' => array(
$this,
'uniqueFieldName',
),
'source' => array(
'name',
),
),
);
$entity_options = array();
$entities = $this->entityTypeManager
->getDefinitions();
foreach ($entities as $entity_type => $entity_info) {
if ($entity_info
->get('field_ui_base_route') || $entity_type == 'ds_views') {
$entity_options[$entity_type] = Unicode::ucfirst(str_replace('_', ' ', $entity_type));
}
}
$form['entities'] = array(
'#title' => $this
->t('Entities'),
'#description' => $this
->t('Select the entities for which this field will be made available.'),
'#type' => 'checkboxes',
'#required' => TRUE,
'#options' => $entity_options,
'#default_value' => isset($field['entities']) ? $field['entities'] : array(),
);
$form['ui_limit'] = array(
'#title' => $this
->t('Limit field'),
'#description' => $this
->t('Limit this field on field UI per bundles and/or view modes. The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'. You may use * to select all, e.g article|*, *|full or *|*. Enter one value per line.'),
'#type' => 'textarea',
'#default_value' => isset($field['ui_limit']) ? $field['ui_limit'] : '',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#weight' => 100,
);
return $form;
}