class EntityDisplayModeAddForm
Same name and namespace in other branches
- 11.x core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php \Drupal\field_ui\Form\EntityDisplayModeAddForm
- 10 core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php \Drupal\field_ui\Form\EntityDisplayModeAddForm
- 8.9.x core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php \Drupal\field_ui\Form\EntityDisplayModeAddForm
Provides the add form for entity display modes.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements \Drupal\Core\Entity\EntityFormInterface extends \Drupal\Core\Form\FormBase
- class \Drupal\field_ui\Form\EntityDisplayModeFormBase extends \Drupal\Core\Entity\EntityForm
- class \Drupal\field_ui\Form\EntityDisplayModeAddForm extends \Drupal\field_ui\Form\EntityDisplayModeFormBase
- class \Drupal\field_ui\Form\EntityDisplayModeFormBase extends \Drupal\Core\Entity\EntityForm
- class \Drupal\Core\Entity\EntityForm implements \Drupal\Core\Entity\EntityFormInterface extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of EntityDisplayModeAddForm
File
-
core/
modules/ field_ui/ src/ Form/ EntityDisplayModeAddForm.php, line 13
Namespace
Drupal\field_ui\FormView source
class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
/**
* The entity type for which the display mode is being created.
*
* @var string
*/
protected $targetEntityTypeId;
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
$this->targetEntityTypeId = $entity_type_id;
$form = parent::buildForm($form, $form_state);
// Change replace_pattern to avoid undesired dots.
$form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
$definition = $this->entityTypeManager
->getDefinition($this->targetEntityTypeId);
$form['#title'] = $this->t('Add new @entity-type %label', [
'@entity-type' => $definition->getLabel(),
'%label' => $this->entityType
->getSingularLabel(),
]);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$form_state->setValueForElement($form['id'], $this->targetEntityTypeId . '.' . $form_state->getValue('id'));
}
/**
* {@inheritdoc}
*/
protected function prepareEntity() {
$definition = $this->entityTypeManager
->getDefinition($this->targetEntityTypeId);
if (!$definition->get('field_ui_base_route') || !$definition->hasViewBuilderClass()) {
throw new NotFoundHttpException();
}
$this->entity
->setTargetType($this->targetEntityTypeId);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.