diff --git a/core/lib/Drupal/Core/Entity/BundleEntityFormBase.php b/core/lib/Drupal/Core/Entity/BundleEntityFormBase.php index 88ad30c..57204d4 100644 --- a/core/lib/Drupal/Core/Entity/BundleEntityFormBase.php +++ b/core/lib/Drupal/Core/Entity/BundleEntityFormBase.php @@ -10,7 +10,7 @@ /** * Class BundleEntityFormBase is a base form for bundle config entities. */ -class BundleEntityFormBase extends EntityForm { +class BundleEntityFormBase extends ConfigEntityForm { /** * Protects the bundle entity's ID property's form element against changes. diff --git a/core/lib/Drupal/Core/Entity/ConfigEntityForm.php b/core/lib/Drupal/Core/Entity/ConfigEntityForm.php new file mode 100644 index 0000000..b08e7bf --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ConfigEntityForm.php @@ -0,0 +1,41 @@ +getFormObject()->getEntity()->getEntityType(); + return (bool) \Drupal::entityQuery($entity_type->id()) + ->condition($entity_type->getKey('id'), $entity_id) + ->execute(); + } + +} diff --git a/core/modules/action/src/ActionAddForm.php b/core/modules/action/src/ActionAddForm.php index 6d8e4aa..9d14ea0 100644 --- a/core/modules/action/src/ActionAddForm.php +++ b/core/modules/action/src/ActionAddForm.php @@ -9,7 +9,6 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Action\ActionManager; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -33,9 +32,7 @@ class ActionAddForm extends ActionFormBase { * @param \Drupal\Core\Action\ActionManager $action_manager * The action plugin manager. */ - public function __construct(EntityStorageInterface $storage, ActionManager $action_manager) { - parent::__construct($storage); - + public function __construct(ActionManager $action_manager) { $this->actionManager = $action_manager; } @@ -44,7 +41,6 @@ public function __construct(EntityStorageInterface $storage, ActionManager $acti */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorage('action'), $container->get('plugin.manager.action') ); } diff --git a/core/modules/action/src/ActionFormBase.php b/core/modules/action/src/ActionFormBase.php index 0b972d4..33150e4 100644 --- a/core/modules/action/src/ActionFormBase.php +++ b/core/modules/action/src/ActionFormBase.php @@ -7,16 +7,14 @@ namespace Drupal\action; -use Drupal\Core\Entity\EntityForm; -use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a base form for action forms. */ -abstract class ActionFormBase extends EntityForm { +abstract class ActionFormBase extends ConfigEntityForm { /** * The action plugin being configured. @@ -26,32 +24,6 @@ protected $plugin; /** - * The action storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $storage; - - /** - * Constructs a new action form. - * - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The action storage. - */ - public function __construct(EntityStorageInterface $storage) { - $this->storage = $storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager')->getStorage('action') - ); - } - - /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { @@ -78,7 +50,7 @@ public function form(array $form, FormStateInterface $form_state) { '#maxlength' => 64, '#description' => $this->t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'), '#machine_name' => array( - 'exists' => array($this, 'exists'), + 'exists' => [static::class, 'exists'], ), ); $form['plugin'] = array( @@ -98,20 +70,6 @@ public function form(array $form, FormStateInterface $form_state) { } /** - * Determines if the action already exists. - * - * @param string $id - * The action ID - * - * @return bool - * TRUE if the action exists, FALSE otherwise. - */ - public function exists($id) { - $action = $this->storage->load($id); - return !empty($action); - } - - /** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 50e4d38..c76d0c7 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -8,7 +8,7 @@ namespace Drupal\block; use Drupal\Component\Utility\Html; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Executable\ExecutableManagerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -22,7 +22,7 @@ /** * Provides form for block instance forms. */ -class BlockForm extends EntityForm { +class BlockForm extends ConfigEntityForm { /** * The block entity. @@ -135,7 +135,7 @@ public function form(array $form, FormStateInterface $form_state) { '#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'), '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity), '#machine_name' => array( - 'exists' => '\Drupal\block\Entity\Block::load', + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', 'source' => array('settings', 'label'), ), diff --git a/core/modules/block_content/src/BlockContentTypeForm.php b/core/modules/block_content/src/BlockContentTypeForm.php index 9474ccc..c061082 100644 --- a/core/modules/block_content/src/BlockContentTypeForm.php +++ b/core/modules/block_content/src/BlockContentTypeForm.php @@ -45,7 +45,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'machine_name', '#default_value' => $block_type->id(), '#machine_name' => array( - 'exists' => '\Drupal\block_content\Entity\BlockContentType::load', + 'exists' => [static::class, 'exists'], ), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, ); diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index 12d65fb..8436215 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -7,7 +7,7 @@ namespace Drupal\comment; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; @@ -18,7 +18,7 @@ /** * Base form controller for category edit forms. */ -class CommentTypeForm extends EntityForm { +class CommentTypeForm extends ConfigEntityForm { /** * Entity manager service. @@ -87,7 +87,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'machine_name', '#default_value' => $comment_type->id(), '#machine_name' => array( - 'exists' => '\Drupal\comment\Entity\CommentType::load', + 'exists' => [static::class, 'exists'], ), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$comment_type->isNew(), diff --git a/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php index 14f4bef..0eb9d4b 100644 --- a/core/modules/config/tests/config_test/src/ConfigTestForm.php +++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php @@ -7,7 +7,7 @@ namespace Drupal\config_test; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -16,7 +16,7 @@ /** * Form controller for the test config edit forms. */ -class ConfigTestForm extends EntityForm { +class ConfigTestForm extends ConfigEntityForm { /** * The entity query. @@ -62,7 +62,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $entity->id(), '#required' => TRUE, '#machine_name' => array( - 'exists' => [$this, 'exists'], + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', ), ); @@ -178,25 +178,4 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirectUrl($this->entity->urlInfo('collection')); } - /** - * Determines if the entity already exists. - * - * @param string|int $entity_id - * The entity ID. - * @param array $element - * The form element. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - * - * @return bool - * TRUE if the entity exists, FALSE otherwise. - */ - public function exists($entity_id, array $element, FormStateInterface $form_state) { - /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ - $entity = $form_state->getFormObject()->getEntity(); - return (bool) $this->entityQuery->get($entity->getEntityTypeId()) - ->condition($entity->getEntityType()->getKey('id'), $entity_id) - ->execute(); - } - } diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php index b4adde6..0232f84 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -8,8 +8,8 @@ namespace Drupal\contact; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Entity\ConfigEntityForm; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\ConfigFormBaseTrait; use Drupal\Core\Form\FormStateInterface; @@ -18,7 +18,7 @@ /** * Base form for contact form edit forms. */ -class ContactFormEditForm extends EntityForm implements ContainerInjectionInterface { +class ContactFormEditForm extends ConfigEntityForm implements ContainerInjectionInterface { use ConfigFormBaseTrait; /** @@ -76,7 +76,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $contact_form->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array( - 'exists' => '\Drupal\contact\Entity\ContactForm::load', + 'exists' => [static::class, 'exists'], ), '#disabled' => !$contact_form->isNew(), ); diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php index 7d79bd7..f828a9b 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php @@ -7,7 +7,7 @@ namespace Drupal\field_ui\Form; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; @@ -16,7 +16,7 @@ /** * Provides the generic base class for entity display mode forms. */ -abstract class EntityDisplayModeFormBase extends EntityForm { +abstract class EntityDisplayModeFormBase extends ConfigEntityForm { /** * The entity query factory. @@ -88,7 +88,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $this->entity->id(), '#field_prefix' => $this->entity->isNew() ? $this->entity->getTargetType() . '.' : '', '#machine_name' => array( - 'exists' => array($this, 'exists'), + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', ), ); @@ -97,25 +97,14 @@ public function form(array $form, FormStateInterface $form_state) { } /** - * Determines if the display mode already exists. - * - * @param string|int $entity_id - * The entity ID. - * @param array $element - * The form element. - * - * @return bool - * TRUE if the display mode exists, FALSE otherwise. + * {@inheritdoc} */ - public function exists($entity_id, array $element) { + public static function exists($entity_id, array $element, FormStateInterface $form_state) { // Do not allow to add internal 'default' view mode. if ($entity_id == 'default') { return TRUE; } - return (bool) $this->queryFactory - ->get($this->entity->getEntityTypeId()) - ->condition('id', $element['#field_prefix'] . $entity_id) - ->execute(); + return parent::exists($element['#field_prefix'] . $entity_id, $element, $form_state); } /** diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php index a528c0d..e3d65c1 100644 --- a/core/modules/filter/src/FilterFormatFormBase.php +++ b/core/modules/filter/src/FilterFormatFormBase.php @@ -7,7 +7,7 @@ namespace Drupal\filter; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; use Drupal\filter\Plugin\Filter\FilterNull; @@ -16,7 +16,7 @@ /** * Provides a base form for a filter format. */ -abstract class FilterFormatFormBase extends EntityForm { +abstract class FilterFormatFormBase extends ConfigEntityForm { /** * The entity query factory. @@ -67,7 +67,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $format->id(), '#maxlength' => 255, '#machine_name' => array( - 'exists' => array($this, 'exists'), + 'exists' => [static::class, 'exists'], 'source' => array('name'), ), '#disabled' => !$format->isNew(), @@ -185,22 +185,6 @@ public function form(array $form, FormStateInterface $form_state) { } /** - * Determines if the format already exists. - * - * @param string $format_id - * The format ID - * - * @return bool - * TRUE if the format exists, FALSE otherwise. - */ - public function exists($format_id) { - return (bool) $this->queryFactory - ->get('filter_format') - ->condition('format', $format_id) - ->execute(); - } - - /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { diff --git a/core/modules/image/src/Form/ImageStyleEditForm.php b/core/modules/image/src/Form/ImageStyleEditForm.php index b3e7f8e..d20db6d 100644 --- a/core/modules/image/src/Form/ImageStyleEditForm.php +++ b/core/modules/image/src/Form/ImageStyleEditForm.php @@ -7,7 +7,6 @@ namespace Drupal\image\Form; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\image\ConfigurableImageEffectInterface; @@ -29,13 +28,10 @@ class ImageStyleEditForm extends ImageStyleFormBase { /** * Constructs an ImageStyleEditForm object. * - * @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage - * The storage. * @param \Drupal\image\ImageEffectManager $image_effect_manager * The image effect manager service. */ - public function __construct(EntityStorageInterface $image_style_storage, ImageEffectManager $image_effect_manager) { - parent::__construct($image_style_storage); + public function __construct(ImageEffectManager $image_effect_manager) { $this->imageEffectManager = $image_effect_manager; } @@ -44,7 +40,6 @@ public function __construct(EntityStorageInterface $image_style_storage, ImageEf */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorage('image_style'), $container->get('plugin.manager.image.effect') ); } diff --git a/core/modules/image/src/Form/ImageStyleFormBase.php b/core/modules/image/src/Form/ImageStyleFormBase.php index f5e432c..e13d42a 100644 --- a/core/modules/image/src/Form/ImageStyleFormBase.php +++ b/core/modules/image/src/Form/ImageStyleFormBase.php @@ -7,15 +7,13 @@ namespace Drupal\image\Form; -use Drupal\Core\Entity\EntityForm; -use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Form\FormStateInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base form for image style add and edit forms. */ -abstract class ImageStyleFormBase extends EntityForm { +abstract class ImageStyleFormBase extends ConfigEntityForm { /** * The entity being used by this form. @@ -25,32 +23,6 @@ protected $entity; /** - * The image style entity storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $imageStyleStorage; - - /** - * Constructs a base class for image style add and edit forms. - * - * @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage - * The image style entity storage. - */ - public function __construct(EntityStorageInterface $image_style_storage) { - $this->imageStyleStorage = $image_style_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager')->getStorage('image_style') - ); - } - - /** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { @@ -64,7 +36,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['name'] = array( '#type' => 'machine_name', '#machine_name' => array( - 'exists' => array($this->imageStyleStorage, 'load'), + 'exists' => [static::class, 'exists'], ), '#default_value' => $this->entity->id(), '#required' => TRUE, diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index e4f8cf5..6d85159 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -83,7 +83,7 @@ public function form(array $form, FormStateInterface $form_state) { '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => $type->isLocked(), '#machine_name' => array( - 'exists' => ['Drupal\node\Entity\NodeType', 'load'], + 'exists' => [static::class, 'exists'], 'source' => array('name'), ), '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array( diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php index 359c5c7..c38cd09 100644 --- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -8,14 +8,14 @@ namespace Drupal\responsive_image; use Drupal\breakpoint\BreakpointManagerInterface; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the responsive image edit/add forms. */ -class ResponsiveImageStyleForm extends EntityForm { +class ResponsiveImageStyleForm extends ConfigEntityForm { /** * The breakpoint manager. @@ -77,7 +77,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'machine_name', '#default_value' => $responsive_image_style->id(), '#machine_name' => array( - 'exists' => '\Drupal\responsive_image\Entity\ResponsiveImageStyle::load', + 'exists' => [static::class, 'exists'], 'source' => array('label'), ), '#disabled' => (bool) $responsive_image_style->id() && $this->operation != 'duplicate', diff --git a/core/modules/search/src/Form/SearchPageFormBase.php b/core/modules/search/src/Form/SearchPageFormBase.php index c8c7641..09f6a5a 100644 --- a/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -7,7 +7,7 @@ namespace Drupal\search\Form; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; @@ -17,7 +17,7 @@ /** * Provides a base form for search pages. */ -abstract class SearchPageFormBase extends EntityForm { +abstract class SearchPageFormBase extends ConfigEntityForm { /** * The entity being used by this form. @@ -103,7 +103,7 @@ public function form(array $form, FormStateInterface $form_state) { '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#machine_name' => array( - 'exists' => array($this, 'exists'), + 'exists' => [static::class, 'exists'], ), ); $form['path'] = array( @@ -127,22 +127,6 @@ public function form(array $form, FormStateInterface $form_state) { } /** - * Determines if the search page entity already exists. - * - * @param string $id - * The search configuration ID. - * - * @return bool - * TRUE if the search configuration exists, FALSE otherwise. - */ - public function exists($id) { - $entity = $this->entityQuery->get('search_page') - ->condition('id', $id) - ->execute(); - return (bool) $entity; - } - - /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { diff --git a/core/modules/shortcut/src/ShortcutSetForm.php b/core/modules/shortcut/src/ShortcutSetForm.php index fd21f7c..fb23b68 100644 --- a/core/modules/shortcut/src/ShortcutSetForm.php +++ b/core/modules/shortcut/src/ShortcutSetForm.php @@ -32,7 +32,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['id'] = array( '#type' => 'machine_name', '#machine_name' => array( - 'exists' => '\Drupal\shortcut\Entity\ShortcutSet::load', + 'exists' => [static::class, 'exists'], 'source' => array('label'), 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-', diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php index d5868b5..b1f2b03 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -9,16 +9,16 @@ use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\Datetime\DateFormatterInterface; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\Core\Entity\EntityForm; /** * Provides a base form for date formats. */ -abstract class DateFormatFormBase extends EntityForm { +abstract class DateFormatFormBase extends ConfigEntityForm { /** * The date formatter service. @@ -60,21 +60,10 @@ public static function create(ContainerInterface $container) { } /** - * Checks for an existing date format. - * - * @param string|int $entity_id - * The entity ID. - * @param array $element - * The form element. - * - * @return bool - * TRUE if this format already exists, FALSE otherwise. + * {@inheritdoc} */ - public function exists($entity_id, array $element) { - return (bool) $this->dateFormatStorage - ->getQuery() - ->condition('id', $element['#field_prefix'] . $entity_id) - ->execute(); + public static function exists($entity_id, array $element, FormStateInterface $form_state) { + return parent::exists($element['#field_prefix'] . $entity_id, $element, $form_state); } /** @@ -95,7 +84,7 @@ public function form(array $form, FormStateInterface $form_state) { '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => array( - 'exists' => array($this, 'exists'), + 'exists' => array(static::class, 'exists'), 'replace_pattern' =>'([^a-z0-9_]+)|(^custom$)', 'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'), ), diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index e175af7..0a304d2 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -12,7 +12,6 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ContentLanguageSettings; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base form for vocabulary edit forms. @@ -20,32 +19,6 @@ class VocabularyForm extends BundleEntityFormBase { /** - * The vocabulary storage. - * - * @var \Drupal\taxonomy\VocabularyStorageInterface. - */ - protected $vocabularyStorage; - - /** - * Constructs a new vocabulary form. - * - * @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage - * The vocabulary storage. - */ - public function __construct(VocabularyStorageInterface $vocabulary_storage) { - $this->vocabularyStorage = $vocabulary_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager')->getStorage('taxonomy_vocabulary') - ); - } - - /** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { @@ -69,7 +42,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $vocabulary->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array( - 'exists' => array($this, 'exists'), + 'exists' => [static::class, 'exists'], 'source' => array('name'), ), ); @@ -144,18 +117,4 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->set('vid', $vocabulary->id()); } - /** - * Determines if the vocabulary already exists. - * - * @param string $vid - * The vocabulary ID. - * - * @return bool - * TRUE if the vocabulary exists, FALSE otherwise. - */ - public function exists($vid) { - $action = $this->vocabularyStorage->load($vid); - return !empty($action); - } - } diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php index ada54dd..3d5fc30 100644 --- a/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -7,13 +7,13 @@ namespace Drupal\user; -use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Form\FormStateInterface; /** * Form controller for the role entity edit forms. */ -class RoleForm extends EntityForm { +class RoleForm extends ConfigEntityForm { /** * {@inheritdoc} @@ -37,7 +37,7 @@ public function form(array $form, FormStateInterface $form_state) { '#size' => 30, '#maxlength' => 64, '#machine_name' => array( - 'exists' => ['\Drupal\user\Entity\Role', 'load'], + 'exists' => [static::class, 'exists'], ), ); $form['weight'] = array(