EntityDisplayModeAddForm.php in Zircon Profile 8
File
core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
View source
<?php
namespace Drupal\field_ui\Form;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
protected $targetEntityTypeId;
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
$this->targetEntityTypeId = $entity_type_id;
$form = parent::buildForm($form, $form_state);
$form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
$definition = $this->entityManager
->getDefinition($this->targetEntityTypeId);
$form['#title'] = $this
->t('Add new %label @entity-type', array(
'%label' => $definition
->getLabel(),
'@entity-type' => $this->entityType
->getLowercaseLabel(),
));
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$form_state
->setValueForElement($form['id'], $this->targetEntityTypeId . '.' . $form_state
->getValue('id'));
}
protected function prepareEntity() {
$definition = $this->entityManager
->getDefinition($this->targetEntityTypeId);
if (!$definition
->get('field_ui_base_route') || !$definition
->hasViewBuilderClass()) {
throw new NotFoundHttpException();
}
$this->entity
->setTargetType($this->targetEntityTypeId);
}
}