public function BlockFieldItem::fieldSettingsForm in Block field 8
Returns a form for the field-level settings.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.
Return value
array The form definition for the field settings.
Overrides FieldItemBase::fieldSettingsForm
File
- src/
Plugin/ Field/ FieldType/ BlockFieldItem.php, line 84
Class
- BlockFieldItem
- Plugin implementation of the 'block_field' field type.
Namespace
Drupal\block_field\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$field = $form_state
->getFormObject()
->getEntity();
/** @var \Drupal\block_field\BlockFieldSelectionManager $block_field_selection_manager */
$block_field_selection_manager = \Drupal::service('plugin.manager.block_field_selection');
$options = $block_field_selection_manager
->getOptions();
$form = [
'#type' => 'container',
'#process' => [
[
get_class($this),
'fieldSettingsAjaxProcess',
],
],
'#element_validate' => [
[
get_class($this),
'fieldSettingsFormValidate',
],
],
];
$form['selection'] = [
'#type' => 'details',
'#title' => $this
->t('Available blocks'),
'#open' => TRUE,
'#tree' => TRUE,
'#process' => [
[
get_class($this),
'formProcessMergeParent',
],
],
];
$form['selection']['selection'] = [
'#type' => 'select',
'#title' => $this
->t('Selection method'),
'#options' => $options,
'#default_value' => $field
->getSetting('selection'),
'#required' => TRUE,
'#ajax' => TRUE,
'#limit_validation_errors' => [],
];
$form['selection']['selection_submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Change selection'),
'#limit_validation_errors' => [],
'#attributes' => [
'class' => [
'js-hide',
],
],
'#submit' => [
[
get_class($this),
'settingsAjaxSubmit',
],
],
];
$form['selection']['selection_settings'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'block_field-settings',
],
],
];
$selection = $block_field_selection_manager
->getSelectionHandler($field);
$form['selection']['selection_settings'] += $selection
->buildConfigurationForm([], $form_state);
return $form;
}