function FieldBlock::blockForm

Same name in other branches
  1. 9 core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::blockForm()
  2. 8.9.x core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::blockForm()
  3. 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 240

Class

FieldBlock
Provides a block that renders a field from an entity.

Namespace

Drupal\layout_builder\Plugin\Block

Code

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'),
        '#options' => $this->getFieldLabelOptions(),
        '#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.