function EntityField::blockForm

Same name in other branches
  1. 4.0.x modules/ctools_block/src/Plugin/Block/EntityField.php \Drupal\ctools_block\Plugin\Block\EntityField::blockForm()

Overrides BlockPluginTrait::blockForm

File

modules/ctools_block/src/Plugin/Block/EntityField.php, line 207

Class

EntityField
Provides a block to a field on an entity.

Namespace

Drupal\ctools_block\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
    $config = $this->getConfiguration();
    $form['formatter_label'] = [
        '#type' => 'select',
        '#title' => $this->t('Label'),
        '#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->getFormatterOptions(),
        '#default_value' => $config['formatter']['type'],
        '#ajax' => [
            'callback' => [
                static::class,
                'formatterSettingsAjaxCallback',
            ],
            'wrapper' => 'formatter-settings-wrapper',
            'effect' => 'fade',
        ],
    ];
    // Add the formatter settings to the form via AJAX.
    $form['#process'][] = [
        $this,
        'formatterSettingsProcessCallback',
    ];
    $form['formatter_settings_wrapper'] = [
        '#prefix' => '<div id="formatter-settings-wrapper">',
        '#suffix' => '</div>',
    ];
    $form['formatter_settings_wrapper']['formatter_settings'] = [
        '#tree' => TRUE,
    ];
    return $form;
}