public function EntityBlock::blockForm in Entity Blocks 8
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ EntityBlock.php, line 91
Class
- EntityBlock
- Provides the block for similar articles.
Namespace
Drupal\entity_block\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this->configuration;
$form['entity'] = [
'#type' => 'entity_autocomplete',
'#title' => $this
->t('Entity'),
'#target_type' => $this->entityTypeName,
'#required' => TRUE,
];
if (isset($config['entity'])) {
if ($entity = $this->entityStorage
->load($config['entity'])) {
$form['entity']['#default_value'] = $entity;
}
}
$view_mode = isset($config['view_mode']) ? $config['view_mode'] : NULL;
$form['view_mode'] = [
'#type' => 'select',
'#title' => $this
->t('View mode'),
'#options' => $this->view_mode_options,
'#default_value' => $view_mode,
];
return $form;
}