public function ConfigPagesBlock::blockForm in Config Pages 8.3
Same name and namespace in other branches
- 8 src/Plugin/Block/ConfigPagesBlock.php \Drupal\config_pages\Plugin\Block\ConfigPagesBlock::blockForm()
- 8.2 src/Plugin/Block/ConfigPagesBlock.php \Drupal\config_pages\Plugin\Block\ConfigPagesBlock::blockForm()
Returns the configuration form elements specific to this block plugin.
Blocks that need to add form elements to the normal block configuration form should implement this method.
Parameters
array $form: The form definition array for the block configuration form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The renderable form array representing the entire configuration form.
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ ConfigPagesBlock.php, line 123
Class
- ConfigPagesBlock
- Provides a generic ConfigPages block.
Namespace
Drupal\config_pages\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
// Get all available ConfigPages types and prepare options list.
$config = $this
->getConfiguration();
$config_pages_types = ConfigPagesType::loadMultiple();
$options = [];
foreach ($config_pages_types as $cp_type) {
$id = $cp_type
->id();
$label = $cp_type
->label();
$options[$id] = $label;
}
$form['config_page_type'] = [
'#type' => 'select',
'#title' => $this
->t('Select ConfigPage type to show'),
'#options' => $options,
'#default_value' => isset($config['config_page_type']) ? $config['config_page_type'] : '',
];
$view_modes = $this->entity_display_repository
->getViewModes('config_pages');
$options = [];
foreach ($view_modes as $id => $view_mode) {
$options[$id] = $view_mode['label'];
}
// Get view modes.
$form['config_page_view_mode'] = [
'#type' => 'select',
'#title' => $this
->t('Select view mode for ConfigPage to show'),
'#options' => $options,
'#default_value' => isset($config['config_page_view_mode']) ? $config['config_page_view_mode'] : '',
];
return $form;
}