function FieldBlock::blockForm
Same name in other branches
- 8.9.x core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::blockForm()
- 10 core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::blockForm()
- 11.x core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::blockForm()
Overrides BlockPluginTrait::blockForm
File
-
core/
modules/ layout_builder/ src/ Plugin/ Block/ FieldBlock.php, line 238
Class
- FieldBlock
- Provides a block that renders a field from an entity.
Namespace
Drupal\layout_builder\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$config = $this->getConfiguration();
$form['formatter'] = [
'#tree' => TRUE,
'#process' => [
[
$this,
'formatterSettingsProcessCallback',
],
],
];
$form['formatter']['label'] = [
'#type' => 'select',
'#title' => $this->t('Label'),
// @todo This is directly copied from
// \Drupal\field_ui\Form\EntityViewDisplayEditForm::getFieldLabelOptions(),
// resolve this in https://www.drupal.org/project/drupal/issues/2933924.
'#options' => [
'above' => $this->t('Above'),
'inline' => $this->t('Inline'),
'hidden' => '- ' . $this->t('Hidden') . ' -',
'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
],
'#default_value' => $config['formatter']['label'],
];
$form['formatter']['type'] = [
'#type' => 'select',
'#title' => $this->t('Formatter'),
'#options' => $this->getApplicablePluginOptions($this->getFieldDefinition()),
'#required' => TRUE,
'#default_value' => $config['formatter']['type'],
'#ajax' => [
'callback' => [
static::class,
'formatterSettingsAjaxCallback',
],
'wrapper' => 'formatter-settings-wrapper',
],
];
// Add the formatter settings to the form via AJAX.
$form['formatter']['settings_wrapper'] = [
'#prefix' => '<div id="formatter-settings-wrapper">',
'#suffix' => '</div>',
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.