/** * Overrides \Drupal\Core\Block\BlockBase::blockForm(). * * Adds body and description fields to the block configuration form. */ public function blockForm($form, FormStateInterface $form_state) { $options = $this->entityManager->getViewModeOptions('block_content'); $form['view_mode'] = array('#type' => 'select', '#options' => $options, '#title' => $this->t('View mode'), '#description' => $this->t('Output the block in this view mode.'), '#default_value' => $this->configuration['view_mode'], '#access' => count($options) > 1); $form['title']['#description'] = $this->t('The title of the block as shown to the user.'); return $form; }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['view_mode'] = array('#type' => 'select', '#options' => $this->entityManager->getViewModeOptions($this->entityType), '#title' => $this->t('View mode'), '#default_value' => $this->options['view_mode']); $label = $this->entityManager->getDefinition($this->entityType)->getLabel(); $target = $this->options['target']; // If the target does not contain tokens, try to load the entity and // display the entity ID to the admin form user. // @todo Use a method to check for tokens in // https://www.drupal.org/node/2396607. if (strpos($this->options['target'], '{{') === FALSE) { // @todo If the entity does not exist, this will will show the config // target identifier. Decide if this is the correct behavior in // https://www.drupal.org/node/2415391. if ($target_entity = $this->entityManager->loadEntityByConfigTarget($this->entityType, $this->options['target'])) { $target = $target_entity->id(); } } $form['target'] = ['#title' => $this->t('@entity_type_label ID', ['@entity_type_label' => $label]), '#type' => 'textfield', '#default_value' => $target]; $form['bypass_access'] = array('#type' => 'checkbox', '#title' => $this->t('Bypass access checks'), '#description' => $this->t('If enabled, access permissions for rendering the entity are not checked.'), '#default_value' => !empty($this->options['bypass_access'])); }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form['view_mode'] = ['#type' => 'select', '#options' => $this->entityManager->getViewModeOptions($this->getDerivativeId()), '#title' => $this->t('View mode'), '#default_value' => $this->configuration['view_mode']]; return $form; }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['view_mode'] = ['#type' => 'select', '#options' => $this->entityManager->getViewModeOptions($this->getEntityTypeId()), '#title' => $this->t('View mode'), '#default_value' => $this->options['view_mode']]; }
/** * {@inheritdoc} */ public function getViewModeOptions($entity_type_id, $include_disabled = FALSE) { return $this->entityManager->getViewModeOptions($entity_type_id, $include_disabled); }