diff --git a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php index 311c309..fc5bd8e 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php @@ -92,11 +92,4 @@ protected function actions(array $form, FormStateInterface $form_state) { return $actions; } - /** - * {@inheritdoc} - */ - public function save(array $form, array &$form_state) { - $this->entity->delete(); - } - } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDeleteFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityDeleteFormBase.php new file mode 100644 index 0000000..21e5898 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ContentEntityDeleteFormBase.php @@ -0,0 +1,24 @@ +entity->delete(); + } + +} diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteFormBase.php b/core/lib/Drupal/Core/Entity/EntityDeleteFormBase.php new file mode 100644 index 0000000..5ec14b9 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityDeleteFormBase.php @@ -0,0 +1,26 @@ +entity->delete(); + } + +} diff --git a/core/modules/action/src/Form/ActionDeleteForm.php b/core/modules/action/src/Form/ActionDeleteForm.php index 0f89e3d..da7f847 100644 --- a/core/modules/action/src/Form/ActionDeleteForm.php +++ b/core/modules/action/src/Form/ActionDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\action\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Builds a form to delete an action. */ -class ActionDeleteForm extends EntityConfirmFormBase { +class ActionDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -40,8 +40,8 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); $this->logger('user')->notice('Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label())); drupal_set_message($this->t('Action %action was deleted', array('%action' => $this->entity->label()))); diff --git a/core/modules/aggregator/src/Form/FeedDeleteForm.php b/core/modules/aggregator/src/Form/FeedDeleteForm.php index 1282b71..737e49f 100644 --- a/core/modules/aggregator/src/Form/FeedDeleteForm.php +++ b/core/modules/aggregator/src/Form/FeedDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\aggregator\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a form for deleting a feed. */ -class FeedDeleteForm extends ContentEntityConfirmFormBase { +class FeedDeleteForm extends ContentEntityDeleteFormBase { /** * {@inheritdoc} diff --git a/core/modules/block/src/Form/BlockDeleteForm.php b/core/modules/block/src/Form/BlockDeleteForm.php index 1567875..ed110f1 100644 --- a/core/modules/block/src/Form/BlockDeleteForm.php +++ b/core/modules/block/src/Form/BlockDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\block\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a deletion confirmation form for the block instance deletion form. */ -class BlockDeleteForm extends EntityConfirmFormBase { +class BlockDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -40,8 +40,9 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message($this->t('The block %name has been removed.', array('%name' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/core/modules/block_content/src/Form/BlockContentDeleteForm.php b/core/modules/block_content/src/Form/BlockContentDeleteForm.php index 259ed6f..c5fd9a5 100644 --- a/core/modules/block_content/src/Form/BlockContentDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\block_content\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a confirmation form for deleting a custom block entity. */ -class BlockContentDeleteForm extends ContentEntityConfirmFormBase { +class BlockContentDeleteForm extends ContentEntityDeleteFormBase { /** * {@inheritdoc} @@ -54,7 +54,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label()))); diff --git a/core/modules/block_content/src/Form/BlockContentTypeAddForm.php b/core/modules/block_content/src/Form/BlockContentTypeAddForm.php index fd63e61..dc1428d 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeAddForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeAddForm.php @@ -7,6 +7,8 @@ namespace Drupal\block_content\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding block content types. */ @@ -15,7 +17,7 @@ class BlockContentTypeAddForm extends BlockContentTypeFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $block_type = $this->entity; diff --git a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php index a1b9e9b..f47e725 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\block_content\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; @@ -16,7 +16,7 @@ /** * Provides a confirmation form for deleting a custom block type entity. */ -class BlockContentTypeDeleteForm extends EntityConfirmFormBase { +class BlockContentTypeDeleteForm extends EntityDeleteFormBase { /** * The query factory to create entity queries. @@ -83,8 +83,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label()))); $this->logger('block_content')->notice('Custom block type %label has been deleted.', array('%label' => $this->entity->label())); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/block_content/src/Form/BlockContentTypeEditForm.php b/core/modules/block_content/src/Form/BlockContentTypeEditForm.php index b4d48ef..3fb4304 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeEditForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeEditForm.php @@ -7,6 +7,8 @@ namespace Drupal\block_content\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding block content types. */ @@ -15,7 +17,7 @@ class BlockContentTypeEditForm extends BlockContentTypeFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $block_type = $this->entity; diff --git a/core/modules/comment/src/Form/CommentTypeAddForm.php b/core/modules/comment/src/Form/CommentTypeAddForm.php index 6669e91..66ce52a 100644 --- a/core/modules/comment/src/Form/CommentTypeAddForm.php +++ b/core/modules/comment/src/Form/CommentTypeAddForm.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding comment types. */ @@ -15,7 +17,7 @@ class CommentTypeAddForm extends CommentTypeFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $block_type = $this->entity; diff --git a/core/modules/comment/src/Form/CommentTypeDeleteForm.php b/core/modules/comment/src/Form/CommentTypeDeleteForm.php index 043aac4..d25b95f 100644 --- a/core/modules/comment/src/Form/CommentTypeDeleteForm.php +++ b/core/modules/comment/src/Form/CommentTypeDeleteForm.php @@ -8,7 +8,7 @@ namespace Drupal\comment\Form; use Drupal\comment\CommentManagerInterface; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; @@ -20,7 +20,7 @@ /** * Provides a confirmation form for deleting a comment type entity. */ -class CommentTypeDeleteForm extends EntityConfirmFormBase { +class CommentTypeDeleteForm extends EntityDeleteFormBase { /** * The query factory to create entity queries. @@ -141,8 +141,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + $form_state->setRedirect('comment.type_list'); drupal_set_message($this->t('Comment type %label has been deleted.', array('%label' => $this->entity->label()))); $this->logger->notice('comment type %label has been deleted.', array('%label' => $this->entity->label())); diff --git a/core/modules/comment/src/Form/CommentTypeEditForm.php b/core/modules/comment/src/Form/CommentTypeEditForm.php index 6242cdb..dd901a6 100644 --- a/core/modules/comment/src/Form/CommentTypeEditForm.php +++ b/core/modules/comment/src/Form/CommentTypeEditForm.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding comment types. */ @@ -15,7 +17,7 @@ class CommentTypeEditForm extends CommentTypeFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $block_type = $this->entity; diff --git a/core/modules/comment/src/Form/DeleteForm.php b/core/modules/comment/src/Form/DeleteForm.php index 061b4db..17443af 100644 --- a/core/modules/comment/src/Form/DeleteForm.php +++ b/core/modules/comment/src/Form/DeleteForm.php @@ -7,13 +7,13 @@ namespace Drupal\comment\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; /** * Provides the comment delete confirmation form. */ -class DeleteForm extends ContentEntityConfirmFormBase { +class DeleteForm extends ContentEntityDeleteFormBase { /** * {@inheritdoc} @@ -47,7 +47,7 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); drupal_set_message($this->t('The comment and all its replies have been deleted.')); diff --git a/core/modules/config/tests/config_test/src/Form/ConfigTestAddForm.php b/core/modules/config/tests/config_test/src/Form/ConfigTestAddForm.php index 76ea44b..a26814b 100644 --- a/core/modules/config/tests/config_test/src/Form/ConfigTestAddForm.php +++ b/core/modules/config/tests/config_test/src/Form/ConfigTestAddForm.php @@ -8,6 +8,7 @@ namespace Drupal\config_test\Form; use Drupal\Component\Utility\String; +use Drupal\Core\Form\FormStateInterface; /** * Provides a form for adding "Test configuration" entities. @@ -17,7 +18,7 @@ class ConfigTestAddForm extends ConfigTestFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); drupal_set_message(String::format('%label configuration has been created.', array('%label' => $this->entity->label()))); diff --git a/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php b/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php index b203008..eb984c7 100644 --- a/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php +++ b/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\config_test\Form; use Drupal\Component\Utility\String; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Delete confirmation form for config_test entities. */ -class ConfigTestDeleteForm extends EntityConfirmFormBase { +class ConfigTestDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -40,8 +40,9 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/core/modules/config/tests/config_test/src/Form/ConfigTestEditForm.php b/core/modules/config/tests/config_test/src/Form/ConfigTestEditForm.php index ee7e443..ae833e1 100644 --- a/core/modules/config/tests/config_test/src/Form/ConfigTestEditForm.php +++ b/core/modules/config/tests/config_test/src/Form/ConfigTestEditForm.php @@ -8,6 +8,7 @@ namespace Drupal\config_test\Form; use Drupal\Component\Utility\String; +use Drupal\Core\Form\FormStateInterface; /** * Provides a form for editing "Test configuration" entities. @@ -17,7 +18,7 @@ class ConfigTestEditForm extends ConfigTestFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); drupal_set_message(String::format('%label configuration has been updated.', array('%label' => $this->entity->label()))); diff --git a/core/modules/contact/src/Form/CategoryAddForm.php b/core/modules/contact/src/Form/CategoryAddForm.php index 719df63..23ec3fc 100644 --- a/core/modules/contact/src/Form/CategoryAddForm.php +++ b/core/modules/contact/src/Form/CategoryAddForm.php @@ -8,6 +8,7 @@ namespace Drupal\contact\Form; use Drupal\contact\CategoryFormBase; +use Drupal\Core\Form\FormStateInterface; /** * Provides a form for adding contact categories. @@ -17,15 +18,15 @@ class CategoryAddForm extends CategoryFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); - $block_type = $this->entity; + $category = $this->entity; $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); - drupal_set_message($this->t('Category %label has been added.', array('%label' => $block_type->label()))); + drupal_set_message($this->t('Category %label has been added.', array('%label' => $category->label()))); $this->logger('contact')->notice('Category %label has been added.', array( - '%label' => $block_type->label(), + '%label' => $category->label(), 'link' => $edit_link, )); } diff --git a/core/modules/contact/src/Form/CategoryDeleteForm.php b/core/modules/contact/src/Form/CategoryDeleteForm.php index cd534d4..1cee026 100644 --- a/core/modules/contact/src/Form/CategoryDeleteForm.php +++ b/core/modules/contact/src/Form/CategoryDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\contact\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Builds the form to delete a contact category. */ -class CategoryDeleteForm extends EntityConfirmFormBase { +class CategoryDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -40,8 +40,9 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message($this->t('Category %label has been deleted.', array('%label' => $this->entity->label()))); $this->logger('contact')->notice('Category %label has been deleted.', array('%label' => $this->entity->label())); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/contact/src/Form/CategoryEditForm.php b/core/modules/contact/src/Form/CategoryEditForm.php index 244f57e..ceedc0f 100644 --- a/core/modules/contact/src/Form/CategoryEditForm.php +++ b/core/modules/contact/src/Form/CategoryEditForm.php @@ -8,6 +8,7 @@ namespace Drupal\contact\Form; use Drupal\contact\CategoryFormBase; +use Drupal\Core\Form\FormStateInterface; /** * Provides a form for editing contact categories. @@ -17,7 +18,7 @@ class CategoryEditForm extends CategoryFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $block_type = $this->entity; diff --git a/core/modules/entity/src/Form/EntityDisplayModeDeleteForm.php b/core/modules/entity/src/Form/EntityDisplayModeDeleteForm.php index 95e535f..dc7249d 100644 --- a/core/modules/entity/src/Form/EntityDisplayModeDeleteForm.php +++ b/core/modules/entity/src/Form/EntityDisplayModeDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\entity\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides the delete form for entity display modes. */ -class EntityDisplayModeDeleteForm extends EntityConfirmFormBase { +class EntityDisplayModeDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -49,12 +49,11 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - parent::submit($form, $form_state); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); $entity_type = $this->entity->getEntityType(); drupal_set_message(t('Deleted the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $entity_type->getLowercaseLabel()))); - $this->entity->delete(); \Drupal::entityManager()->clearCachedFieldDefinitions(); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/core/modules/entity/src/Form/EntityDisplayModeFormBase.php b/core/modules/entity/src/Form/EntityDisplayModeFormBase.php index 11b39e5..2cef86e 100644 --- a/core/modules/entity/src/Form/EntityDisplayModeFormBase.php +++ b/core/modules/entity/src/Form/EntityDisplayModeFormBase.php @@ -122,8 +122,9 @@ public function exists($entity_id, array $element) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message(t('Saved the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()))); - $this->entity->save(); \Drupal::entityManager()->clearCachedFieldDefinitions(); $form_state->setRedirect('entity.' . $this->entity->getEntityTypeId() . '_list'); } diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php index ec5dd88..b6cdbdf 100644 --- a/core/modules/field/src/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php @@ -295,7 +295,7 @@ function testEntityFormDisplayExtractFormValues() { $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->instance->bundle)); // Build the form for all fields. - $display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'default'); + $display = entity_get_form_display($entity_type, $this->fieldTestData->instance->bundle, 'add'); $form = array(); $form_state = new FormState(); $display->buildForm($entity_init, $form, $form_state); diff --git a/core/modules/filter/src/FilterFormatAddForm.php b/core/modules/filter/src/FilterFormatAddForm.php index 8c6ad4a..1fa6f73 100644 --- a/core/modules/filter/src/FilterFormatAddForm.php +++ b/core/modules/filter/src/FilterFormatAddForm.php @@ -24,8 +24,8 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - parent::submit($form, $form_state); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); drupal_set_message($this->t('Added text format %format.', array('%format' => $this->entity->label()))); return $this->entity; } diff --git a/core/modules/filter/src/FilterFormatEditForm.php b/core/modules/filter/src/FilterFormatEditForm.php index ab437ac..a32e73f 100644 --- a/core/modules/filter/src/FilterFormatEditForm.php +++ b/core/modules/filter/src/FilterFormatEditForm.php @@ -32,8 +32,8 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - parent::submit($form, $form_state); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); drupal_set_message($this->t('The text format %format has been updated.', array('%format' => $this->entity->label()))); return $this->entity; } diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php index 65159dd..b6077a3 100644 --- a/core/modules/filter/src/FilterFormatFormBase.php +++ b/core/modules/filter/src/FilterFormatFormBase.php @@ -249,10 +249,16 @@ public function submit(array $form, FormStateInterface $form_state) { } } } - $format->save(); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); // Save user permissions. - if ($permission = $format->getPermissionName()) { + if ($permission = $this->entity->getPermissionName()) { foreach ($form_state->getValue('roles') as $rid => $enabled) { user_role_change_permissions($rid, array($permission => $enabled)); } diff --git a/core/modules/image/src/Form/ImageStyleDeleteForm.php b/core/modules/image/src/Form/ImageStyleDeleteForm.php index e490fa6..05538d1 100644 --- a/core/modules/image/src/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/src/Form/ImageStyleDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\image\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Creates a form to delete an image style. */ -class ImageStyleDeleteForm extends EntityConfirmFormBase { +class ImageStyleDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -64,7 +64,14 @@ public function form(array $form, FormStateInterface $form_state) { */ public function submit(array $form, FormStateInterface $form_state) { $this->entity->set('replacementID', $form_state->getValue('replacement')); - $this->entity->delete(); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message($this->t('Style %name was deleted.', array('%name' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/core/modules/image/src/Form/ImageStyleEditForm.php b/core/modules/image/src/Form/ImageStyleEditForm.php index e1ff08a..888dfb2 100644 --- a/core/modules/image/src/Form/ImageStyleEditForm.php +++ b/core/modules/image/src/Form/ImageStyleEditForm.php @@ -213,13 +213,19 @@ public function effectSave($form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function save(array $form, FormStateInterface $form_state) { + public function submit(array $form, FormStateInterface $form_state) { + parent::submit($form, $form_state); // Update image effect weights. if (!$form_state->isValueEmpty('effects')) { $this->updateEffectWeights($form_state->getValue('effects')); } + } + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); drupal_set_message($this->t('Changes to the style have been saved.')); } diff --git a/core/modules/image/src/Form/ImageStyleFormBase.php b/core/modules/image/src/Form/ImageStyleFormBase.php index af35482..776df8c 100644 --- a/core/modules/image/src/Form/ImageStyleFormBase.php +++ b/core/modules/image/src/Form/ImageStyleFormBase.php @@ -77,7 +77,8 @@ public function form(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $this->entity->save(); + parent::save($form, $form_state); + $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); } diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php index 54dfb7f..c4e1617 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\menu_link_content\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; @@ -17,7 +17,7 @@ /** * Provides a delete form for content menu links. */ -class MenuLinkContentDeleteForm extends ContentEntityConfirmFormBase { +class MenuLinkContentDeleteForm extends ContentEntityDeleteFormBase { /** * Logger channel. @@ -66,7 +66,7 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $t_args = array('%title' => $this->entity->getTitle()); diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 83528b5..7143f75 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -69,8 +69,8 @@ function menu_ui_permission() { function menu_ui_entity_type_build(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ $entity_types['menu'] - ->setFormClass('add', 'Drupal\menu_ui\MenuForm') - ->setFormClass('edit', 'Drupal\menu_ui\MenuForm') + ->setFormClass('add', 'Drupal\menu_ui\Form\MenuAddForm') + ->setFormClass('edit', 'Drupal\menu_ui\Form\MenuEditForm') ->setFormClass('delete', 'Drupal\menu_ui\Form\MenuDeleteForm') ->setListBuilderClass('Drupal\menu_ui\MenuListBuilder') ->setLinkTemplate('add-form', 'menu_ui.menu_add') diff --git a/core/modules/menu_ui/src/Form/MenuAddForm.php b/core/modules/menu_ui/src/Form/MenuAddForm.php new file mode 100644 index 0000000..60794af --- /dev/null +++ b/core/modules/menu_ui/src/Form/MenuAddForm.php @@ -0,0 +1,30 @@ +entity; + $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + + drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label()))); + $this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link)); + } + +} diff --git a/core/modules/menu_ui/src/Form/MenuEditForm.php b/core/modules/menu_ui/src/Form/MenuEditForm.php new file mode 100644 index 0000000..f53360f --- /dev/null +++ b/core/modules/menu_ui/src/Form/MenuEditForm.php @@ -0,0 +1,30 @@ +entity; + $edit_link = $this->l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + + drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label()))); + $this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link)); + } + +} diff --git a/core/modules/menu_ui/src/Form/MenuFormBase.php b/core/modules/menu_ui/src/Form/MenuFormBase.php new file mode 100644 index 0000000..75e3356 --- /dev/null +++ b/core/modules/menu_ui/src/Form/MenuFormBase.php @@ -0,0 +1,389 @@ + TRUE); + + /** + * Constructs a MenuFormBase object. + * + * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory + * The factory for entity queries. + * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager + * The menu link manager. + * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree + * The menu tree service. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator. + */ + public function __construct(QueryFactory $entity_query_factory, MenuLinkManagerInterface $menu_link_manager, MenuLinkTreeInterface $menu_tree, LinkGeneratorInterface $link_generator) { + $this->entityQueryFactory = $entity_query_factory; + $this->menuLinkManager = $menu_link_manager; + $this->menuTree = $menu_tree; + $this->linkGenerator = $link_generator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.query'), + $container->get('plugin.manager.menu.link'), + $container->get('menu.link_tree'), + $container->get('link_generator') + ); + } + + /** + * {@inheritdoc} + */ + public function form(array $form, FormStateInterface $form_state) { + $menu = $this->entity; + + if ($this->operation == 'edit') { + $form['#title'] = $this->t('Edit menu %label', array('%label' => $menu->label())); + } + + $form['label'] = array( + '#type' => 'textfield', + '#title' => $this->t('Title'), + '#default_value' => $menu->label(), + '#required' => TRUE, + ); + $form['id'] = array( + '#type' => 'machine_name', + '#title' => $this->t('Menu name'), + '#default_value' => $menu->id(), + '#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI, + '#description' => $this->t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'), + '#machine_name' => array( + 'exists' => array($this, 'menuNameExists'), + 'source' => array('label'), + 'replace_pattern' => '[^a-z0-9-]+', + 'replace' => '-', + ), + // A menu's machine name cannot be changed. + '#disabled' => !$menu->isNew() || $menu->isLocked(), + ); + $form['description'] = array( + '#type' => 'textfield', + '#title' => t('Administrative summary'), + '#maxlength' => 512, + '#default_value' => $menu->description, + ); + + $form['langcode'] = array( + '#type' => 'language_select', + '#title' => t('Menu language'), + '#languages' => LanguageInterface::STATE_ALL, + '#default_value' => $menu->language()->getId(), + ); + + // Add menu links administration form for existing menus. + if (!$menu->isNew() || $menu->isLocked()) { + // Form API supports constructing and validating self-contained sections + // within forms, but does not allow handling the form section's submission + // equally separated yet. Therefore, we use a $form_state key to point to + // the parents of the form section. + // @see self::submitOverviewForm() + $form_state['menu_overview_form_parents'] = array('links'); + $form['links'] = array(); + $form['links'] = $this->buildOverviewForm($form['links'], $form_state); + } + + return parent::form($form, $form_state); + } + + /** + * Returns whether a menu name already exists. + * + * @param string $value + * The name of the menu. + * + * @return bool + * Returns TRUE if the menu already exists, FALSE otherwise. + */ + public function menuNameExists($value) { + // Check first to see if a menu with this ID exists. + if ($this->entityQueryFactory->get('menu')->condition('id', $value)->range(0, 1)->count()->execute()) { + return TRUE; + } + + // Check for a link assigned to this menu. + return $this->menuLinkManager->menuNameInUse($value); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + + $menu = $this->entity; + if (!$menu->isNew() || $menu->isLocked()) { + $this->submitOverviewForm($form, $form_state); + } + + $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); + } + + /** + * Form constructor to edit an entire menu tree at once. + * + * Shows for one menu the menu links accessible to the current user and + * relevant operations. + * + * This form constructor can be integrated as a section into another form. It + * relies on the following keys in $form_state: + * - menu: A menu entity. + * - menu_overview_form_parents: An array containing the parent keys to this + * form. + * Forms integrating this section should call menu_overview_form_submit() from + * their form submit handler. + */ + protected function buildOverviewForm(array &$form, FormStateInterface $form_state) { + // Ensure that menu_overview_form_submit() knows the parents of this form + // section. + $form['#tree'] = TRUE; + $form['#theme'] = 'menu_overview_form'; + $form_state->setIfNotExists('menu_overview_form_parents', array()); + + $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/css/menu.admin.css'); + + $tree = $this->menuTree->load($this->entity->id(), new MenuTreeParameters()); + + // We indicate that a menu administrator is running the menu access check. + $this->getRequest()->attributes->set('_menu_admin', TRUE); + $manipulators = array( + array('callable' => 'menu.default_tree_manipulators:checkAccess'), + array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), + ); + $tree = $this->menuTree->transform($tree, $manipulators); + $this->getRequest()->attributes->set('_menu_admin', FALSE); + + // Determine the delta; the number of weights to be made available. + $count = function(array $tree) { + $sum = function ($carry, MenuLinkTreeElement $item) { + return $carry + $item->count(); + }; + return array_reduce($tree, $sum); + }; + $delta = max($count($tree), 50); + + $form = array_merge($form, $this->buildOverviewTreeForm($tree, $delta)); + $destination = $this->getUrlGenerator()->getPathFromRoute('menu_ui.menu_edit', array('menu' => $this->entity->id())); + $url = $destination = $this->url('menu_link_content.link_add', array('menu' => $this->entity->id()), array('query' => array('destination' => $destination))); + $form['#empty_text'] = $this->t('There are no menu links yet. Add link.', array('@url' => $url)); + + return $form; + } + + /** + * Recursive helper function for buildOverviewForm(). + * + * @param $tree + * The tree retrieved by \Drupal\Core\Menu\MenuLinkTreeInterface::load(). + * @param $delta + * The default number of menu items used in the menu weight selector is 50. + * + * @return array + * The overview tree form. + */ + protected function buildOverviewTreeForm($tree, $delta) { + $form = &$this->overviewTreeForm; + foreach ($tree as $element) { + /** @var \Drupal\Core\Menu\MenuLinkInterface $link */ + $link = $element->link; + if ($link) { + $id = 'menu_plugin_id:' . $link->getPluginId(); + $form[$id]['#item'] = $element; + $form[$id]['#attributes'] = $link->isHidden() ? array('class' => array('menu-disabled')) : array('class' => array('menu-enabled')); + $form[$id]['title']['#markup'] = $this->linkGenerator->generateFromUrl($link->getTitle(), $link->getUrlObject(), $link->getOptions()); + if ($link->isHidden()) { + $form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')'; + } + elseif (($url = $link->getUrlObject()) && !$url->isExternal() && $url->getRouteName() == 'user.page') { + $form[$id]['title']['#markup'] .= ' (' . $this->t('logged in users only') . ')'; + } + + $form[$id]['enabled'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Enable @title menu link', array('@title' => $link->getTitle())), + '#title_display' => 'invisible', + '#default_value' => !$link->isHidden(), + ); + $form[$id]['weight'] = array( + '#type' => 'weight', + '#delta' => $delta, + '#default_value' => $link->getWeight(), + '#title' => $this->t('Weight for @title', array('@title' => $link->getTitle())), + '#title_display' => 'invisible', + ); + $form[$id]['id'] = array( + '#type' => 'hidden', + '#value' => $link->getPluginId(), + ); + $form[$id]['parent'] = array( + '#type' => 'hidden', + '#default_value' => $link->getParent(), + ); + // Build a list of operations. + $operations = array(); + $operations['edit'] = array( + 'title' => $this->t('Edit'), + ); + // Allow for a custom edit link per plugin. + $edit_route = $link->getEditRoute(); + if ($edit_route) { + $operations['edit'] += $edit_route; + // Bring the user back to the menu overview. + $operations['edit']['query']['destination'] = $this->entity->url(); + } + else { + // Fall back to the standard edit link. + $operations['edit'] += array( + 'route_name' => 'menu_ui.link_edit', + 'route_parameters' => array('menu_link_plugin' => $link->getPluginId()), + ); + } + // Links can either be reset or deleted, not both. + if ($link->isResettable()) { + $operations['reset'] = array( + 'title' => $this->t('Reset'), + 'route_name' => 'menu_ui.link_reset', + 'route_parameters' => array('menu_link_plugin' => $link->getPluginId()), + ); + } + elseif ($delete_link = $link->getDeleteRoute()) { + $operations['delete'] = $delete_link; + $operations['delete']['query']['destination'] = $this->entity->url(); + $operations['delete']['title'] = $this->t('Delete'); + } + if ($link->isTranslatable()) { + $operations['translate'] = array( + 'title' => $this->t('Translate'), + ) + (array) $link->getTranslateRoute(); + } + $form[$id]['operations'] = array( + '#type' => 'operations', + '#links' => $operations, + ); + } + + if ($element->subtree) { + $this->buildOverviewTreeForm($element->subtree, $delta); + } + } + return $form; + } + + /** + * Submit handler for the menu overview form. + * + * This function takes great care in saving parent items first, then items + * underneath them. Saving items in the incorrect order can break the tree. + */ + protected function submitOverviewForm(array $complete_form, FormStateInterface $form_state) { + // Form API supports constructing and validating self-contained sections + // within forms, but does not allow to handle the form section's submission + // equally separated yet. Therefore, we use a $form_state key to point to + // the parents of the form section. + $parents = $form_state['menu_overview_form_parents']; + $input = NestedArray::getValue($form_state['input'], $parents); + $form = &NestedArray::getValue($complete_form, $parents); + + // When dealing with saving menu items, the order in which these items are + // saved is critical. If a changed child item is saved before its parent, + // the child item could be saved with an invalid path past its immediate + // parent. To prevent this, save items in the form in the same order they + // are sent, ensuring parents are saved first, then their children. + // See http://drupal.org/node/181126#comment-632270 + $order = is_array($input) ? array_flip(array_keys($input)) : array(); + // Update our original form with the new order. + $form = array_intersect_key(array_merge($order, $form), $form); + + $fields = array('weight', 'parent', 'enabled'); + foreach (Element::children($form) as $id) { + if (isset($form[$id]['#item'])) { + $element = $form[$id]; + $updated_values = array(); + // Update any fields that have changed in this menu item. + foreach ($fields as $field) { + if ($element[$field]['#value'] != $element[$field]['#default_value']) { + // Hidden is a special case, the form value needs to be reversed. + if ($field == 'enabled') { + $updated_values['hidden'] = $element['enabled']['#value'] ? 0 : 1; + } + else { + $updated_values[$field] = $element[$field]['#value']; + } + } + } + if ($updated_values) { + // Use the ID from the actual plugin instance since the hidden value + // in the form could be tampered with. + $this->menuLinkManager->updateDefinition($element['#item']->link->getPLuginId(), $updated_values); + } + } + } + } + +} diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php deleted file mode 100644 index 302a9e2..0000000 --- a/core/modules/menu_ui/src/MenuForm.php +++ /dev/null @@ -1,399 +0,0 @@ - TRUE); - - /** - * Constructs a MenuForm object. - * - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory - * The factory for entity queries. - * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager - * The menu link manager. - * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree - * The menu tree service. - * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator - * The link generator. - */ - public function __construct(QueryFactory $entity_query_factory, MenuLinkManagerInterface $menu_link_manager, MenuLinkTreeInterface $menu_tree, LinkGeneratorInterface $link_generator) { - $this->entityQueryFactory = $entity_query_factory; - $this->menuLinkManager = $menu_link_manager; - $this->menuTree = $menu_tree; - $this->linkGenerator = $link_generator; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.query'), - $container->get('plugin.manager.menu.link'), - $container->get('menu.link_tree'), - $container->get('link_generator') - ); - } - - /** - * {@inheritdoc} - */ - public function form(array $form, FormStateInterface $form_state) { - $menu = $this->entity; - - if ($this->operation == 'edit') { - $form['#title'] = $this->t('Edit menu %label', array('%label' => $menu->label())); - } - - $form['label'] = array( - '#type' => 'textfield', - '#title' => $this->t('Title'), - '#default_value' => $menu->label(), - '#required' => TRUE, - ); - $form['id'] = array( - '#type' => 'machine_name', - '#title' => $this->t('Menu name'), - '#default_value' => $menu->id(), - '#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI, - '#description' => $this->t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'), - '#machine_name' => array( - 'exists' => array($this, 'menuNameExists'), - 'source' => array('label'), - 'replace_pattern' => '[^a-z0-9-]+', - 'replace' => '-', - ), - // A menu's machine name cannot be changed. - '#disabled' => !$menu->isNew() || $menu->isLocked(), - ); - $form['description'] = array( - '#type' => 'textfield', - '#title' => t('Administrative summary'), - '#maxlength' => 512, - '#default_value' => $menu->description, - ); - - $form['langcode'] = array( - '#type' => 'language_select', - '#title' => t('Menu language'), - '#languages' => LanguageInterface::STATE_ALL, - '#default_value' => $menu->language()->getId(), - ); - - // Add menu links administration form for existing menus. - if (!$menu->isNew() || $menu->isLocked()) { - // Form API supports constructing and validating self-contained sections - // within forms, but does not allow handling the form section's submission - // equally separated yet. Therefore, we use a $form_state key to point to - // the parents of the form section. - // @see self::submitOverviewForm() - $form_state['menu_overview_form_parents'] = array('links'); - $form['links'] = array(); - $form['links'] = $this->buildOverviewForm($form['links'], $form_state); - } - - return parent::form($form, $form_state); - } - - /** - * Returns whether a menu name already exists. - * - * @param string $value - * The name of the menu. - * - * @return bool - * Returns TRUE if the menu already exists, FALSE otherwise. - */ - public function menuNameExists($value) { - // Check first to see if a menu with this ID exists. - if ($this->entityQueryFactory->get('menu')->condition('id', $value)->range(0, 1)->count()->execute()) { - return TRUE; - } - - // Check for a link assigned to this menu. - return $this->menuLinkManager->menuNameInUse($value); - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $menu = $this->entity; - if (!$menu->isNew() || $menu->isLocked()) { - $this->submitOverviewForm($form, $form_state); - } - - $status = $menu->save(); - - $edit_link = $this->linkGenerator->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); - if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label()))); - $this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link)); - } - else { - drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label()))); - $this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link)); - } - - $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); - } - - /** - * Form constructor to edit an entire menu tree at once. - * - * Shows for one menu the menu links accessible to the current user and - * relevant operations. - * - * This form constructor can be integrated as a section into another form. It - * relies on the following keys in $form_state: - * - menu: A menu entity. - * - menu_overview_form_parents: An array containing the parent keys to this - * form. - * Forms integrating this section should call menu_overview_form_submit() from - * their form submit handler. - */ - protected function buildOverviewForm(array &$form, FormStateInterface $form_state) { - // Ensure that menu_overview_form_submit() knows the parents of this form - // section. - $form['#tree'] = TRUE; - $form['#theme'] = 'menu_overview_form'; - $form_state->setIfNotExists('menu_overview_form_parents', array()); - - $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/css/menu.admin.css'); - - $tree = $this->menuTree->load($this->entity->id(), new MenuTreeParameters()); - - // We indicate that a menu administrator is running the menu access check. - $this->getRequest()->attributes->set('_menu_admin', TRUE); - $manipulators = array( - array('callable' => 'menu.default_tree_manipulators:checkAccess'), - array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), - ); - $tree = $this->menuTree->transform($tree, $manipulators); - $this->getRequest()->attributes->set('_menu_admin', FALSE); - - // Determine the delta; the number of weights to be made available. - $count = function(array $tree) { - $sum = function ($carry, MenuLinkTreeElement $item) { - return $carry + $item->count(); - }; - return array_reduce($tree, $sum); - }; - $delta = max($count($tree), 50); - - $form = array_merge($form, $this->buildOverviewTreeForm($tree, $delta)); - $destination = $this->getUrlGenerator()->getPathFromRoute('menu_ui.menu_edit', array('menu' => $this->entity->id())); - $url = $destination = $this->url('menu_link_content.link_add', array('menu' => $this->entity->id()), array('query' => array('destination' => $destination))); - $form['#empty_text'] = $this->t('There are no menu links yet. Add link.', array('@url' => $url)); - - return $form; - } - - /** - * Recursive helper function for buildOverviewForm(). - * - * @param $tree - * The tree retrieved by \Drupal\Core\Menu\MenuLinkTreeInterface::load(). - * @param $delta - * The default number of menu items used in the menu weight selector is 50. - * - * @return array - * The overview tree form. - */ - protected function buildOverviewTreeForm($tree, $delta) { - $form = &$this->overviewTreeForm; - foreach ($tree as $element) { - /** @var \Drupal\Core\Menu\MenuLinkInterface $link */ - $link = $element->link; - if ($link) { - $id = 'menu_plugin_id:' . $link->getPluginId(); - $form[$id]['#item'] = $element; - $form[$id]['#attributes'] = $link->isHidden() ? array('class' => array('menu-disabled')) : array('class' => array('menu-enabled')); - $form[$id]['title']['#markup'] = $this->linkGenerator->generateFromUrl($link->getTitle(), $link->getUrlObject(), $link->getOptions()); - if ($link->isHidden()) { - $form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')'; - } - elseif (($url = $link->getUrlObject()) && !$url->isExternal() && $url->getRouteName() == 'user.page') { - $form[$id]['title']['#markup'] .= ' (' . $this->t('logged in users only') . ')'; - } - - $form[$id]['enabled'] = array( - '#type' => 'checkbox', - '#title' => $this->t('Enable @title menu link', array('@title' => $link->getTitle())), - '#title_display' => 'invisible', - '#default_value' => !$link->isHidden(), - ); - $form[$id]['weight'] = array( - '#type' => 'weight', - '#delta' => $delta, - '#default_value' => $link->getWeight(), - '#title' => $this->t('Weight for @title', array('@title' => $link->getTitle())), - '#title_display' => 'invisible', - ); - $form[$id]['id'] = array( - '#type' => 'hidden', - '#value' => $link->getPluginId(), - ); - $form[$id]['parent'] = array( - '#type' => 'hidden', - '#default_value' => $link->getParent(), - ); - // Build a list of operations. - $operations = array(); - $operations['edit'] = array( - 'title' => $this->t('Edit'), - ); - // Allow for a custom edit link per plugin. - $edit_route = $link->getEditRoute(); - if ($edit_route) { - $operations['edit'] += $edit_route; - // Bring the user back to the menu overview. - $operations['edit']['query']['destination'] = $this->entity->url(); - } - else { - // Fall back to the standard edit link. - $operations['edit'] += array( - 'route_name' => 'menu_ui.link_edit', - 'route_parameters' => array('menu_link_plugin' => $link->getPluginId()), - ); - } - // Links can either be reset or deleted, not both. - if ($link->isResettable()) { - $operations['reset'] = array( - 'title' => $this->t('Reset'), - 'route_name' => 'menu_ui.link_reset', - 'route_parameters' => array('menu_link_plugin' => $link->getPluginId()), - ); - } - elseif ($delete_link = $link->getDeleteRoute()) { - $operations['delete'] = $delete_link; - $operations['delete']['query']['destination'] = $this->entity->url(); - $operations['delete']['title'] = $this->t('Delete'); - } - if ($link->isTranslatable()) { - $operations['translate'] = array( - 'title' => $this->t('Translate'), - ) + (array) $link->getTranslateRoute(); - } - $form[$id]['operations'] = array( - '#type' => 'operations', - '#links' => $operations, - ); - } - - if ($element->subtree) { - $this->buildOverviewTreeForm($element->subtree, $delta); - } - } - return $form; - } - - /** - * Submit handler for the menu overview form. - * - * This function takes great care in saving parent items first, then items - * underneath them. Saving items in the incorrect order can break the tree. - */ - protected function submitOverviewForm(array $complete_form, FormStateInterface $form_state) { - // Form API supports constructing and validating self-contained sections - // within forms, but does not allow to handle the form section's submission - // equally separated yet. Therefore, we use a $form_state key to point to - // the parents of the form section. - $parents = $form_state['menu_overview_form_parents']; - $input = NestedArray::getValue($form_state['input'], $parents); - $form = &NestedArray::getValue($complete_form, $parents); - - // When dealing with saving menu items, the order in which these items are - // saved is critical. If a changed child item is saved before its parent, - // the child item could be saved with an invalid path past its immediate - // parent. To prevent this, save items in the form in the same order they - // are sent, ensuring parents are saved first, then their children. - // See http://drupal.org/node/181126#comment-632270 - $order = is_array($input) ? array_flip(array_keys($input)) : array(); - // Update our original form with the new order. - $form = array_intersect_key(array_merge($order, $form), $form); - - $fields = array('weight', 'parent', 'enabled'); - foreach (Element::children($form) as $id) { - if (isset($form[$id]['#item'])) { - $element = $form[$id]; - $updated_values = array(); - // Update any fields that have changed in this menu item. - foreach ($fields as $field) { - if ($element[$field]['#value'] != $element[$field]['#default_value']) { - // Hidden is a special case, the form value needs to be reversed. - if ($field == 'enabled') { - $updated_values['hidden'] = $element['enabled']['#value'] ? 0 : 1; - } - else { - $updated_values[$field] = $element[$field]['#value']; - } - } - } - if ($updated_values) { - // Use the ID from the actual plugin instance since the hidden value - // in the form could be tampered with. - $this->menuLinkManager->updateDefinition($element['#item']->link->getPLuginId(), $updated_values); - } - } - } - } - -} diff --git a/core/modules/node/src/Entity/NodeType.php b/core/modules/node/src/Entity/NodeType.php index 91ce4f7..cde847e 100644 --- a/core/modules/node/src/Entity/NodeType.php +++ b/core/modules/node/src/Entity/NodeType.php @@ -21,8 +21,8 @@ * controllers = { * "access" = "Drupal\node\NodeTypeAccessControlHandler", * "form" = { - * "add" = "Drupal\node\NodeTypeForm", - * "edit" = "Drupal\node\NodeTypeForm", + * "add" = "Drupal\node\Form\NodeTypeAddForm", + * "edit" = "Drupal\node\Form\NodeTypeEditForm", * "delete" = "Drupal\node\Form\NodeTypeDeleteConfirm" * }, * "list_builder" = "Drupal\node\NodeTypeListBuilder", diff --git a/core/modules/node/src/Form/NodeAddForm.php b/core/modules/node/src/Form/NodeAddForm.php index 1c0f63f..21f4a0f 100644 --- a/core/modules/node/src/Form/NodeAddForm.php +++ b/core/modules/node/src/Form/NodeAddForm.php @@ -7,6 +7,8 @@ namespace Drupal\node\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding nodes. */ @@ -15,7 +17,7 @@ class NodeAddForm extends NodeFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); /** @var \Drupal\node\NodeInterface $node */ diff --git a/core/modules/node/src/Form/NodeDeleteForm.php b/core/modules/node/src/Form/NodeDeleteForm.php index c8465bb..08f6840 100644 --- a/core/modules/node/src/Form/NodeDeleteForm.php +++ b/core/modules/node/src/Form/NodeDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\node\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\UrlGeneratorInterface; @@ -16,7 +16,7 @@ /** * Provides a form for deleting a node. */ -class NodeDeleteForm extends ContentEntityConfirmFormBase { +class NodeDeleteForm extends ContentEntityDeleteFormBase { /** * The URL generator. @@ -72,7 +72,7 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $this->logger('content')->notice('@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); diff --git a/core/modules/node/src/Form/NodeEditForm.php b/core/modules/node/src/Form/NodeEditForm.php index 910c7c6..93dd5fc 100644 --- a/core/modules/node/src/Form/NodeEditForm.php +++ b/core/modules/node/src/Form/NodeEditForm.php @@ -7,6 +7,8 @@ namespace Drupal\node\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for editing nodes. */ @@ -15,7 +17,7 @@ class NodeEditForm extends NodeFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); /** @var \Drupal\node\NodeInterface $node */ diff --git a/core/modules/node/src/Form/NodeTypeAddForm.php b/core/modules/node/src/Form/NodeTypeAddForm.php new file mode 100644 index 0000000..6639d67 --- /dev/null +++ b/core/modules/node/src/Form/NodeTypeAddForm.php @@ -0,0 +1,31 @@ +entity; + $t_args = array('%name' => $type->label()); + + drupal_set_message(t('The content type %name has been added.', $t_args)); + $context = array_merge($t_args, array('link' => l(t('View'), 'admin/structure/types'))); + $this->logger('node')->notice('Added content type %name.', $context); + } + +} diff --git a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php index 3631b33..1dadc75 100644 --- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php @@ -7,8 +7,8 @@ namespace Drupal\node\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,7 +16,7 @@ /** * Provides a form for content type deletion. */ -class NodeTypeDeleteConfirm extends EntityConfirmFormBase { +class NodeTypeDeleteConfirm extends EntityDeleteFormBase { /** * The database connection. @@ -83,8 +83,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + $t_args = array('%name' => $this->entity->label()); drupal_set_message(t('The content type %name has been deleted.', $t_args)); $this->logger('node')->notice('Deleted content type %name.', $t_args); diff --git a/core/modules/node/src/Form/NodeTypeEditForm.php b/core/modules/node/src/Form/NodeTypeEditForm.php new file mode 100644 index 0000000..b80e72a --- /dev/null +++ b/core/modules/node/src/Form/NodeTypeEditForm.php @@ -0,0 +1,29 @@ +entity; + $t_args = array('%name' => $type->label()); + + drupal_set_message(t('The content type %name has been updated.', $t_args)); + } + +} diff --git a/core/modules/node/src/Form/NodeTypeFormBase.php b/core/modules/node/src/Form/NodeTypeFormBase.php new file mode 100644 index 0000000..abcc0b5 --- /dev/null +++ b/core/modules/node/src/Form/NodeTypeFormBase.php @@ -0,0 +1,196 @@ +entity; + if ($this->operation == 'add') { + $form['#title'] = String::checkPlain($this->t('Add content type')); + } + elseif ($this->operation == 'edit') { + $form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label())); + } + + $node_settings = $type->getModuleSettings('node'); + // Prepare node options to be used for 'checkboxes' form element. + $keys = array_keys(array_filter($node_settings['options'])); + $node_settings['options'] = array_combine($keys, $keys); + $form['name'] = array( + '#title' => t('Name'), + '#type' => 'textfield', + '#default_value' => $type->name, + '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the Add content page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), + '#required' => TRUE, + '#size' => 30, + ); + + $form['type'] = array( + '#type' => 'machine_name', + '#default_value' => $type->id(), + '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, + '#disabled' => $type->isLocked(), + '#machine_name' => array( + 'exists' => 'node_type_load', + '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( + '%node-add' => t('Add content'), + )), + ); + + $form['description'] = array( + '#title' => t('Description'), + '#type' => 'textarea', + '#default_value' => $type->description, + '#description' => t('Describe this content type. The text will be displayed on the Add content page.'), + ); + + $form['additional_settings'] = array( + '#type' => 'vertical_tabs', + '#attached' => array( + 'library' => array('node/drupal.content_types'), + ), + ); + + $form['submission'] = array( + '#type' => 'details', + '#title' => t('Submission form settings'), + '#group' => 'additional_settings', + '#open' => TRUE, + ); + $form['submission']['title_label'] = array( + '#title' => t('Title field label'), + '#type' => 'textfield', + '#default_value' => $type->title_label, + '#required' => TRUE, + ); + $form['submission']['preview'] = array( + '#type' => 'radios', + '#title' => t('Preview before submitting'), + '#parents' => array('settings', 'node', 'preview'), + '#default_value' => $node_settings['preview'], + '#options' => array( + DRUPAL_DISABLED => t('Disabled'), + DRUPAL_OPTIONAL => t('Optional'), + DRUPAL_REQUIRED => t('Required'), + ), + ); + $form['submission']['help'] = array( + '#type' => 'textarea', + '#title' => t('Explanation or submission guidelines'), + '#default_value' => $type->help, + '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'), + ); + $form['workflow'] = array( + '#type' => 'details', + '#title' => t('Publishing options'), + '#group' => 'additional_settings', + ); + $form['workflow']['options'] = array('#type' => 'checkboxes', + '#title' => t('Default options'), + '#parents' => array('settings', 'node', 'options'), + '#default_value' => $node_settings['options'], + '#options' => array( + 'status' => t('Published'), + 'promote' => t('Promoted to front page'), + 'sticky' => t('Sticky at top of lists'), + 'revision' => t('Create new revision'), + ), + '#description' => t('Users with the Administer content permission will be able to override these options.'), + ); + if ($this->moduleHandler->moduleExists('language')) { + $form['language'] = array( + '#type' => 'details', + '#title' => t('Language settings'), + '#group' => 'additional_settings', + ); + + $language_configuration = language_get_default_configuration('node', $type->id()); + $form['language']['language_configuration'] = array( + '#type' => 'language_configuration', + '#entity_information' => array( + 'entity_type' => 'node', + 'bundle' => $type->id(), + ), + '#default_value' => $language_configuration, + ); + } + $form['display'] = array( + '#type' => 'details', + '#title' => t('Display settings'), + '#group' => 'additional_settings', + ); + $form['display']['submitted'] = array( + '#type' => 'checkbox', + '#title' => t('Display author and date information.'), + '#parents' => array('settings', 'node', 'submitted'), + '#default_value' => $node_settings['submitted'], + '#description' => t('Author username and publish date will be displayed.'), + ); + return $form; + } + + /** + * {@inheritdoc} + */ + protected function actions(array $form, FormStateInterface $form_state) { + $actions = parent::actions($form, $form_state); + $actions['submit']['#value'] = t('Save content type'); + $actions['delete']['#value'] = t('Delete content type'); + return $actions; + } + + /** + * {@inheritdoc} + */ + public function validate(array $form, FormStateInterface $form_state) { + parent::validate($form, $form_state); + + $id = trim($form_state->getValue('type')); + // '0' is invalid, since elsewhere we check it using empty(). + if ($id == '0') { + $form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id))); + } + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, FormStateInterface $form_state) { + parent::submit($form, $form_state); + + $type = $this->entity; + $type->type = trim($type->id()); + $type->name = trim($type->name); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + + $form_state->setRedirect('node.overview_types'); + } + +} diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php deleted file mode 100644 index c99045f..0000000 --- a/core/modules/node/src/NodeTypeForm.php +++ /dev/null @@ -1,200 +0,0 @@ -entity; - if ($this->operation == 'add') { - $form['#title'] = String::checkPlain($this->t('Add content type')); - } - elseif ($this->operation == 'edit') { - $form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label())); - } - - $node_settings = $type->getModuleSettings('node'); - // Prepare node options to be used for 'checkboxes' form element. - $keys = array_keys(array_filter($node_settings['options'])); - $node_settings['options'] = array_combine($keys, $keys); - $form['name'] = array( - '#title' => t('Name'), - '#type' => 'textfield', - '#default_value' => $type->name, - '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the Add content page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), - '#required' => TRUE, - '#size' => 30, - ); - - $form['type'] = array( - '#type' => 'machine_name', - '#default_value' => $type->id(), - '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, - '#disabled' => $type->isLocked(), - '#machine_name' => array( - 'exists' => 'node_type_load', - '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( - '%node-add' => t('Add content'), - )), - ); - - $form['description'] = array( - '#title' => t('Description'), - '#type' => 'textarea', - '#default_value' => $type->description, - '#description' => t('Describe this content type. The text will be displayed on the Add content page.'), - ); - - $form['additional_settings'] = array( - '#type' => 'vertical_tabs', - '#attached' => array( - 'library' => array('node/drupal.content_types'), - ), - ); - - $form['submission'] = array( - '#type' => 'details', - '#title' => t('Submission form settings'), - '#group' => 'additional_settings', - '#open' => TRUE, - ); - $form['submission']['title_label'] = array( - '#title' => t('Title field label'), - '#type' => 'textfield', - '#default_value' => $type->title_label, - '#required' => TRUE, - ); - $form['submission']['preview'] = array( - '#type' => 'radios', - '#title' => t('Preview before submitting'), - '#parents' => array('settings', 'node', 'preview'), - '#default_value' => $node_settings['preview'], - '#options' => array( - DRUPAL_DISABLED => t('Disabled'), - DRUPAL_OPTIONAL => t('Optional'), - DRUPAL_REQUIRED => t('Required'), - ), - ); - $form['submission']['help'] = array( - '#type' => 'textarea', - '#title' => t('Explanation or submission guidelines'), - '#default_value' => $type->help, - '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'), - ); - $form['workflow'] = array( - '#type' => 'details', - '#title' => t('Publishing options'), - '#group' => 'additional_settings', - ); - $form['workflow']['options'] = array('#type' => 'checkboxes', - '#title' => t('Default options'), - '#parents' => array('settings', 'node', 'options'), - '#default_value' => $node_settings['options'], - '#options' => array( - 'status' => t('Published'), - 'promote' => t('Promoted to front page'), - 'sticky' => t('Sticky at top of lists'), - 'revision' => t('Create new revision'), - ), - '#description' => t('Users with the Administer content permission will be able to override these options.'), - ); - if ($this->moduleHandler->moduleExists('language')) { - $form['language'] = array( - '#type' => 'details', - '#title' => t('Language settings'), - '#group' => 'additional_settings', - ); - - $language_configuration = language_get_default_configuration('node', $type->id()); - $form['language']['language_configuration'] = array( - '#type' => 'language_configuration', - '#entity_information' => array( - 'entity_type' => 'node', - 'bundle' => $type->id(), - ), - '#default_value' => $language_configuration, - ); - } - $form['display'] = array( - '#type' => 'details', - '#title' => t('Display settings'), - '#group' => 'additional_settings', - ); - $form['display']['submitted'] = array( - '#type' => 'checkbox', - '#title' => t('Display author and date information.'), - '#parents' => array('settings', 'node', 'submitted'), - '#default_value' => $node_settings['submitted'], - '#description' => t('Author username and publish date will be displayed.'), - ); - return $form; - } - - /** - * {@inheritdoc} - */ - protected function actions(array $form, FormStateInterface $form_state) { - $actions = parent::actions($form, $form_state); - $actions['submit']['#value'] = t('Save content type'); - $actions['delete']['#value'] = t('Delete content type'); - return $actions; - } - - /** - * {@inheritdoc} - */ - public function validate(array $form, FormStateInterface $form_state) { - parent::validate($form, $form_state); - - $id = trim($form_state->getValue('type')); - // '0' is invalid, since elsewhere we check it using empty(). - if ($id == '0') { - $form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id))); - } - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $type = $this->entity; - $type->type = trim($type->id()); - $type->name = trim($type->name); - - $status = $type->save(); - - $t_args = array('%name' => $type->label()); - - if ($status == SAVED_UPDATED) { - drupal_set_message(t('The content type %name has been updated.', $t_args)); - } - elseif ($status == SAVED_NEW) { - drupal_set_message(t('The content type %name has been added.', $t_args)); - $context = array_merge($t_args, array('link' => l(t('View'), 'admin/structure/types'))); - $this->logger('node')->notice('Added content type %name.', $context); - } - - $form_state->setRedirect('node.overview_types'); - } - -} diff --git a/core/modules/node/src/NodeTypeListBuilder.php b/core/modules/node/src/NodeTypeListBuilder.php index 779672a..d10a4b4 100644 --- a/core/modules/node/src/NodeTypeListBuilder.php +++ b/core/modules/node/src/NodeTypeListBuilder.php @@ -31,7 +31,7 @@ class NodeTypeListBuilder extends ConfigEntityListBuilder { protected $urlGenerator; /** - * Constructs a NodeTypeForm object. + * Constructs a NodeTypeFormBase object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. diff --git a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php index c15d823..cc32d07 100644 --- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php +++ b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php @@ -7,11 +7,11 @@ namespace Drupal\responsive_image\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -class ResponsiveImageMappingDeleteForm extends EntityConfirmFormBase { +class ResponsiveImageMappingDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -37,8 +37,9 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message($this->t('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label()))); $this->logger('responsive_image')->notice('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label())); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php index 180c75a..7a21ca9 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php @@ -121,9 +121,10 @@ public function validate(array $form, FormStateInterface $form_state) { * Overrides Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + /** @var \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping */ $responsive_image_mapping = $this->entity; - $responsive_image_mapping->save(); $this->logger('responsive_image')->notice('Responsive image mapping @label saved.', array('@label' => $responsive_image_mapping->label())); drupal_set_message($this->t('Responsive image mapping %label saved.', array('%label' => $responsive_image_mapping->label()))); diff --git a/core/modules/search/src/Form/SearchPageDeleteForm.php b/core/modules/search/src/Form/SearchPageDeleteForm.php index 8797961..7ed977c 100644 --- a/core/modules/search/src/Form/SearchPageDeleteForm.php +++ b/core/modules/search/src/Form/SearchPageDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\search\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a deletion confirm form for search. */ -class SearchPageDeleteForm extends EntityConfirmFormBase { +class SearchPageDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -40,8 +40,9 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + $form_state->setRedirectUrl($this->getCancelUrl()); drupal_set_message($this->t('The %label search page has been deleted.', array('%label' => $this->entity->label()))); } diff --git a/core/modules/search/src/Form/SearchPageFormBase.php b/core/modules/search/src/Form/SearchPageFormBase.php index 7c49fd8..cbc24b0 100644 --- a/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -177,7 +177,7 @@ public function submit(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $this->entity->save(); + parent::save($form, $form_state); $form_state->setRedirect('search.settings'); } diff --git a/core/modules/shortcut/src/Form/ShortcutDeleteForm.php b/core/modules/shortcut/src/Form/ShortcutDeleteForm.php index f53076a..ecdf3b9 100644 --- a/core/modules/shortcut/src/Form/ShortcutDeleteForm.php +++ b/core/modules/shortcut/src/Form/ShortcutDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\shortcut\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Builds the shortcut link deletion form. */ -class ShortcutDeleteForm extends ContentEntityConfirmFormBase { +class ShortcutDeleteForm extends ContentEntityDeleteFormBase { /** * {@inheritdoc} @@ -49,7 +49,7 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php b/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php index 4be29ca..e38bccc 100644 --- a/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php +++ b/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\shortcut\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\shortcut\ShortcutSetStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,7 +16,7 @@ /** * Builds the shortcut set deletion form. */ -class ShortcutSetDeleteForm extends EntityConfirmFormBase { +class ShortcutSetDeleteForm extends EntityDeleteFormBase { /** * The database connection. @@ -101,8 +101,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + $form_state->setRedirect('shortcut.set_admin'); drupal_set_message(t('The shortcut set %title has been deleted.', array('%title' => $this->entity->label()))); } diff --git a/core/modules/shortcut/src/ShortcutSetForm.php b/core/modules/shortcut/src/ShortcutSetForm.php index cb5f43f..fa19d09 100644 --- a/core/modules/shortcut/src/ShortcutSetForm.php +++ b/core/modules/shortcut/src/ShortcutSetForm.php @@ -64,9 +64,10 @@ public function validate(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + $entity = $this->entity; $is_new = !$entity->getOriginalId(); - $entity->save(); if ($is_new) { drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array('%set_name' => $entity->label()))); diff --git a/core/modules/system/src/Form/DateFormatAddForm.php b/core/modules/system/src/Form/DateFormatAddForm.php index 22333e7..06eb38d 100644 --- a/core/modules/system/src/Form/DateFormatAddForm.php +++ b/core/modules/system/src/Form/DateFormatAddForm.php @@ -26,8 +26,8 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - parent::submit($form, $form_state); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); drupal_set_message(t('Custom date format added.')); } diff --git a/core/modules/system/src/Form/DateFormatDeleteForm.php b/core/modules/system/src/Form/DateFormatDeleteForm.php index a97b94a..56d3024 100644 --- a/core/modules/system/src/Form/DateFormatDeleteForm.php +++ b/core/modules/system/src/Form/DateFormatDeleteForm.php @@ -8,7 +8,7 @@ namespace Drupal\system\Form; use Drupal\Core\Datetime\DateFormatter; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,7 +16,7 @@ /** * Builds a form to delete a date format. */ -class DateFormatDeleteForm extends EntityConfirmFormBase { +class DateFormatDeleteForm extends EntityDeleteFormBase { /** * The date formatter service. @@ -71,8 +71,9 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message(t('Removed date format %format.', array('%format' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/system/src/Form/DateFormatEditForm.php b/core/modules/system/src/Form/DateFormatEditForm.php index 84fda1c..ca739cc 100644 --- a/core/modules/system/src/Form/DateFormatEditForm.php +++ b/core/modules/system/src/Form/DateFormatEditForm.php @@ -40,8 +40,8 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - parent::submit($form, $form_state); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); drupal_set_message(t('Custom date format updated.')); } diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php index 311f5db..fcf07dc 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -174,11 +174,18 @@ public function validate(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submit(array $form, FormStateInterface $form_state) { - $form_state->setRedirect('system.date_format_list'); $form_state->setValue('pattern', trim($form_state->getValue('date_format_pattern'))); parent::submit($form, $form_state); - $this->entity->save(); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + + $form_state->setRedirect('system.date_format_list'); } } diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php index 05f2b6a..b5eb45f 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\entity_test; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides the entity_test delete form. */ -class EntityTestDeleteForm extends ContentEntityConfirmFormBase { +class EntityTestDeleteForm extends ContentEntityDeleteFormBase { /** * {@inheritdoc} @@ -34,7 +34,7 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { parent::save($form, $form_state); $entity = $this->entity; diff --git a/core/modules/system/tests/modules/entity_test/src/Form/EntityTestAddForm.php b/core/modules/system/tests/modules/entity_test/src/Form/EntityTestAddForm.php index 0494ba6..2c75426 100644 --- a/core/modules/system/tests/modules/entity_test/src/Form/EntityTestAddForm.php +++ b/core/modules/system/tests/modules/entity_test/src/Form/EntityTestAddForm.php @@ -7,6 +7,8 @@ namespace Drupal\entity_test\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding "Test entity" entities. */ @@ -15,7 +17,7 @@ class EntityTestAddForm extends EntityTestFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $entity = $this->entity; diff --git a/core/modules/system/tests/modules/entity_test/src/Form/EntityTestEditForm.php b/core/modules/system/tests/modules/entity_test/src/Form/EntityTestEditForm.php index 0f1b56c..730429e 100644 --- a/core/modules/system/tests/modules/entity_test/src/Form/EntityTestEditForm.php +++ b/core/modules/system/tests/modules/entity_test/src/Form/EntityTestEditForm.php @@ -7,6 +7,8 @@ namespace Drupal\entity_test\Form; +use Drupal\Core\Form\FormStateInterface; + /** * Provides a form for adding "Test entity" entities. */ @@ -15,7 +17,7 @@ class EntityTestEditForm extends EntityTestFormBase { /** * {@inheritdoc} */ - public function save(array $form, array &$form_state) { + public function save(array $form, FormStateInterface &$form_state) { parent::save($form, $form_state); $entity = $this->entity; diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php index 3927c34..d5c1e56 100644 --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -21,7 +21,8 @@ * "storage" = "Drupal\taxonomy\VocabularyStorage", * "list_builder" = "Drupal\taxonomy\VocabularyListBuilder", * "form" = { - * "default" = "Drupal\taxonomy\VocabularyForm", + * "add" = "Drupal\taxonomy\Form\VocabularyAddForm", + * "edit" = "Drupal\taxonomy\Form\VocabularyEditForm", * "reset" = "Drupal\taxonomy\Form\VocabularyResetForm", * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" * } diff --git a/core/modules/taxonomy/src/Form/TermDeleteForm.php b/core/modules/taxonomy/src/Form/TermDeleteForm.php index bb9b4ff..2175dfe 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -11,12 +11,12 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteFormBase; /** * Provides a deletion confirmation form for taxonomy term. */ -class TermDeleteForm extends ContentEntityConfirmFormBase { +class TermDeleteForm extends ContentEntityDeleteFormBase { /** * {@inheritdoc} diff --git a/core/modules/taxonomy/src/Form/VocabularyAddForm.php b/core/modules/taxonomy/src/Form/VocabularyAddForm.php new file mode 100644 index 0000000..9bfd978 --- /dev/null +++ b/core/modules/taxonomy/src/Form/VocabularyAddForm.php @@ -0,0 +1,31 @@ +entity; + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + + drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); + $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); + $form_state->setRedirectUrl($vocabulary->urlInfo('overview-form')); + } + +} diff --git a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php index e938b6e..b9115b3 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\taxonomy\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a deletion confirmation form for taxonomy vocabulary. */ -class VocabularyDeleteForm extends EntityConfirmFormBase { +class VocabularyDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -54,8 +54,9 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + drupal_set_message($this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label()))); $this->logger('taxonomy')->notice('Deleted vocabulary %name.', array('%name' => $this->entity->label())); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/taxonomy/src/Form/VocabularyEditForm.php b/core/modules/taxonomy/src/Form/VocabularyEditForm.php new file mode 100644 index 0000000..4f85359 --- /dev/null +++ b/core/modules/taxonomy/src/Form/VocabularyEditForm.php @@ -0,0 +1,31 @@ +entity; + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + + drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); + $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); + $form_state->setRedirect('taxonomy.vocabulary_list'); + } + +} diff --git a/core/modules/taxonomy/src/Form/VocabularyFormBase.php b/core/modules/taxonomy/src/Form/VocabularyFormBase.php new file mode 100644 index 0000000..86fdde3 --- /dev/null +++ b/core/modules/taxonomy/src/Form/VocabularyFormBase.php @@ -0,0 +1,170 @@ +entity; + if ($vocabulary->isNew()) { + $form['#title'] = $this->t('Add vocabulary'); + } + else { + $form['#title'] = $this->t('Edit vocabulary'); + } + + $form['name'] = array( + '#type' => 'textfield', + '#title' => $this->t('Name'), + '#default_value' => $vocabulary->name, + '#maxlength' => 255, + '#required' => TRUE, + ); + $form['vid'] = array( + '#type' => 'machine_name', + '#default_value' => $vocabulary->id(), + '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, + '#machine_name' => array( + 'exists' => 'taxonomy_vocabulary_load', + 'source' => array('name'), + ), + ); + $form['description'] = array( + '#type' => 'textfield', + '#title' => $this->t('Description'), + '#default_value' => $vocabulary->description, + ); + + // $form['langcode'] is not wrapped in an + // if ($this->moduleHandler->moduleExists('language')) check because the + // language_select form element works also without the language module being + // installed. http://drupal.org/node/1749954 documents the new element. + $form['langcode'] = array( + '#type' => 'language_select', + '#title' => $this->t('Vocabulary language'), + '#languages' => LanguageInterface::STATE_ALL, + '#default_value' => $vocabulary->language()->getId(), + ); + if ($this->moduleHandler->moduleExists('language')) { + $form['default_terms_language'] = array( + '#type' => 'details', + '#title' => $this->t('Terms language'), + '#open' => TRUE, + ); + $form['default_terms_language']['default_language'] = array( + '#type' => 'language_configuration', + '#entity_information' => array( + 'entity_type' => 'taxonomy_term', + 'bundle' => $vocabulary->id(), + ), + '#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary->id()), + ); + } + // Set the hierarchy to "multiple parents" by default. This simplifies the + // vocabulary form and standardizes the term form. + $form['hierarchy'] = array( + '#type' => 'value', + '#value' => '0', + ); + + return parent::form($form, $form_state, $vocabulary); + } + + /** + * {@inheritdoc} + */ + protected function actions(array $form, FormStateInterface $form_state) { + // If we are displaying the delete confirmation skip the regular actions. + if (empty($form_state['confirm_delete'])) { + $actions = parent::actions($form, $form_state); + // Add the language configuration submit handler. This is needed because + // the submit button has custom submit handlers. + if ($this->moduleHandler->moduleExists('language')) { + array_unshift($actions['submit']['#submit'], 'language_configuration_element_submit'); + array_unshift($actions['submit']['#submit'], array($this, 'languageConfigurationSubmit')); + } + // We cannot leverage the regular submit handler definition because we + // have button-specific ones here. Hence we need to explicitly set it for + // the submit action, otherwise it would be ignored. + if ($this->moduleHandler->moduleExists('content_translation')) { + array_unshift($actions['submit']['#submit'], 'content_translation_language_configuration_element_submit'); + } + return $actions; + } + else { + return array(); + } + } + + /** + * Submit handler to update the bundle for the default language configuration. + */ + public function languageConfigurationSubmit(array &$form, FormStateInterface $form_state) { + $vocabulary = $this->entity; + // Delete the old language settings for the vocabulary, if the machine name + // is changed. + if ($vocabulary && $vocabulary->id() && $vocabulary->id() != $form_state->getValue('vid')) { + language_clear_default_configuration('taxonomy_term', $vocabulary->id()); + } + // Since the machine name is not known yet, and it can be changed anytime, + // we have to also update the bundle property for the default language + // configuration in order to have the correct bundle value. + $form_state['language']['default_language']['bundle'] = $form_state->getValue('vid'); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, FormStateInterface $form_state) { + parent::submit($form, $form_state); + + $vocabulary = $this->entity; + + // Prevent leading and trailing spaces in vocabulary names. + $vocabulary->name = trim($vocabulary->name); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + + $vocabulary = $this->entity; + + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + switch ($status) { + case SAVED_NEW: + drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); + $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); + $form_state->setRedirectUrl($vocabulary->urlInfo('overview-form')); + break; + + case SAVED_UPDATED: + drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); + $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); + $form_state->setRedirect('taxonomy.vocabulary_list'); + break; + } + + $form_state->setValue('vid', $vocabulary->id()); + $form_state['vid'] = $vocabulary->id(); + } + +} diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php deleted file mode 100644 index d34d3e2..0000000 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ /dev/null @@ -1,160 +0,0 @@ -entity; - if ($vocabulary->isNew()) { - $form['#title'] = $this->t('Add vocabulary'); - } - else { - $form['#title'] = $this->t('Edit vocabulary'); - } - - $form['name'] = array( - '#type' => 'textfield', - '#title' => $this->t('Name'), - '#default_value' => $vocabulary->name, - '#maxlength' => 255, - '#required' => TRUE, - ); - $form['vid'] = array( - '#type' => 'machine_name', - '#default_value' => $vocabulary->id(), - '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, - '#machine_name' => array( - 'exists' => 'taxonomy_vocabulary_load', - 'source' => array('name'), - ), - ); - $form['description'] = array( - '#type' => 'textfield', - '#title' => $this->t('Description'), - '#default_value' => $vocabulary->description, - ); - - // $form['langcode'] is not wrapped in an - // if ($this->moduleHandler->moduleExists('language')) check because the - // language_select form element works also without the language module being - // installed. http://drupal.org/node/1749954 documents the new element. - $form['langcode'] = array( - '#type' => 'language_select', - '#title' => $this->t('Vocabulary language'), - '#languages' => LanguageInterface::STATE_ALL, - '#default_value' => $vocabulary->language()->getId(), - ); - if ($this->moduleHandler->moduleExists('language')) { - $form['default_terms_language'] = array( - '#type' => 'details', - '#title' => $this->t('Terms language'), - '#open' => TRUE, - ); - $form['default_terms_language']['default_language'] = array( - '#type' => 'language_configuration', - '#entity_information' => array( - 'entity_type' => 'taxonomy_term', - 'bundle' => $vocabulary->id(), - ), - '#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary->id()), - ); - } - // Set the hierarchy to "multiple parents" by default. This simplifies the - // vocabulary form and standardizes the term form. - $form['hierarchy'] = array( - '#type' => 'value', - '#value' => '0', - ); - - return parent::form($form, $form_state, $vocabulary); - } - - /** - * {@inheritdoc} - */ - protected function actions(array $form, FormStateInterface $form_state) { - // If we are displaying the delete confirmation skip the regular actions. - if (empty($form_state['confirm_delete'])) { - $actions = parent::actions($form, $form_state); - // Add the language configuration submit handler. This is needed because - // the submit button has custom submit handlers. - if ($this->moduleHandler->moduleExists('language')) { - array_unshift($actions['submit']['#submit'], 'language_configuration_element_submit'); - array_unshift($actions['submit']['#submit'], array($this, 'languageConfigurationSubmit')); - } - // We cannot leverage the regular submit handler definition because we - // have button-specific ones here. Hence we need to explicitly set it for - // the submit action, otherwise it would be ignored. - if ($this->moduleHandler->moduleExists('content_translation')) { - array_unshift($actions['submit']['#submit'], 'content_translation_language_configuration_element_submit'); - } - return $actions; - } - else { - return array(); - } - } - - /** - * Submit handler to update the bundle for the default language configuration. - */ - public function languageConfigurationSubmit(array &$form, FormStateInterface $form_state) { - $vocabulary = $this->entity; - // Delete the old language settings for the vocabulary, if the machine name - // is changed. - if ($vocabulary && $vocabulary->id() && $vocabulary->id() != $form_state->getValue('vid')) { - language_clear_default_configuration('taxonomy_term', $vocabulary->id()); - } - // Since the machine name is not known yet, and it can be changed anytime, - // we have to also update the bundle property for the default language - // configuration in order to have the correct bundle value. - $form_state['language']['default_language']['bundle'] = $form_state->getValue('vid'); - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $vocabulary = $this->entity; - - // Prevent leading and trailing spaces in vocabulary names. - $vocabulary->name = trim($vocabulary->name); - - $status = $vocabulary->save(); - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); - switch ($status) { - case SAVED_NEW: - drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); - $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); - $form_state->setRedirectUrl($vocabulary->urlInfo('overview-form')); - break; - - case SAVED_UPDATED: - drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); - $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); - $form_state->setRedirect('taxonomy.vocabulary_list'); - break; - } - - $form_state->setValue('vid', $vocabulary->id()); - $form_state['vid'] = $vocabulary->id(); - } - -} diff --git a/core/modules/user/src/Entity/Role.php b/core/modules/user/src/Entity/Role.php index e5a6f8b..96422e2 100644 --- a/core/modules/user/src/Entity/Role.php +++ b/core/modules/user/src/Entity/Role.php @@ -22,7 +22,8 @@ * "access" = "Drupal\user\RoleAccessControlHandler", * "list_builder" = "Drupal\user\RoleListBuilder", * "form" = { - * "default" = "Drupal\user\RoleForm", + * "add" = "Drupal\user\Form\RoleAddForm", + * "edit" = "Drupal\user\Form\RoleEditForm", * "delete" = "Drupal\user\Form\UserRoleDelete" * } * }, diff --git a/core/modules/user/src/Form/RoleAddForm.php b/core/modules/user/src/Form/RoleAddForm.php new file mode 100644 index 0000000..1b01ee1 --- /dev/null +++ b/core/modules/user/src/Form/RoleAddForm.php @@ -0,0 +1,30 @@ +entity; + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + + drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); + $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link)); + } + +} diff --git a/core/modules/user/src/Form/RoleEditForm.php b/core/modules/user/src/Form/RoleEditForm.php new file mode 100644 index 0000000..40984c6 --- /dev/null +++ b/core/modules/user/src/Form/RoleEditForm.php @@ -0,0 +1,30 @@ +entity; + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()->getRouteName()); + + drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); + $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link)); + } + +} diff --git a/core/modules/user/src/Form/RoleFormBase.php b/core/modules/user/src/Form/RoleFormBase.php new file mode 100644 index 0000000..ef683da --- /dev/null +++ b/core/modules/user/src/Form/RoleFormBase.php @@ -0,0 +1,73 @@ +entity; + $form['label'] = array( + '#type' => 'textfield', + '#title' => $this->t('Role name'), + '#default_value' => $entity->label(), + '#size' => 30, + '#required' => TRUE, + '#maxlength' => 64, + '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), + ); + $form['id'] = array( + '#type' => 'machine_name', + '#default_value' => $entity->id(), + '#required' => TRUE, + '#disabled' => !$entity->isNew(), + '#size' => 30, + '#maxlength' => 64, + '#machine_name' => array( + 'exists' => 'user_role_load', + ), + ); + $form['weight'] = array( + '#type' => 'value', + '#value' => $entity->getWeight(), + ); + + return parent::form($form, $form_state, $entity); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, FormStateInterface $form_state) { + parent::submit($form, $form_state); + + $entity = $this->entity; + + // Prevent leading and trailing spaces in role names. + $entity->set('label', trim($entity->label())); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); + + $form_state->setRedirect('user.role_list'); + } + +} diff --git a/core/modules/user/src/Form/UserRoleDelete.php b/core/modules/user/src/Form/UserRoleDelete.php index bdd4f08..eba9c88 100644 --- a/core/modules/user/src/Form/UserRoleDelete.php +++ b/core/modules/user/src/Form/UserRoleDelete.php @@ -7,14 +7,14 @@ namespace Drupal\user\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a deletion confirmation form for Role entity. */ -class UserRoleDelete extends EntityConfirmFormBase { +class UserRoleDelete extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -41,7 +41,8 @@ public function getConfirmText() { * {@inheritdoc} */ public function submit(array $form, FormStateInterface $form_state) { - $this->entity->delete(); + parent::save($form, $form_state); + $this->logger('user')->notice('Role %name has been deleted.', array('%name' => $this->entity->label())); drupal_set_message($this->t('Role %name has been deleted.', array('%name' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php deleted file mode 100644 index 55e0ccd..0000000 --- a/core/modules/user/src/RoleForm.php +++ /dev/null @@ -1,74 +0,0 @@ -entity; - $form['label'] = array( - '#type' => 'textfield', - '#title' => $this->t('Role name'), - '#default_value' => $entity->label(), - '#size' => 30, - '#required' => TRUE, - '#maxlength' => 64, - '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), - ); - $form['id'] = array( - '#type' => 'machine_name', - '#default_value' => $entity->id(), - '#required' => TRUE, - '#disabled' => !$entity->isNew(), - '#size' => 30, - '#maxlength' => 64, - '#machine_name' => array( - 'exists' => 'user_role_load', - ), - ); - $form['weight'] = array( - '#type' => 'value', - '#value' => $entity->getWeight(), - ); - - return parent::form($form, $form_state, $entity); - } - - /** - * {@inheritdoc} - */ - public function save(array $form, FormStateInterface $form_state) { - $entity = $this->entity; - - // Prevent leading and trailing spaces in role names. - $entity->set('label', trim($entity->label())); - $status = $entity->save(); - - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); - if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); - $this->logger('user')->notice('Role %label has been updated.', array('%label' => $entity->label(), 'link' => $edit_link)); - } - else { - drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); - $this->logger('user')->notice('Role %label has been added.', array('%label' => $entity->label(), 'link' => $edit_link)); - } - $form_state->setRedirect('user.role_list'); - } - -} diff --git a/core/modules/views_ui/src/ViewAddForm.php b/core/modules/views_ui/src/ViewAddForm.php index 8717ff9..b7c2a1e 100644 --- a/core/modules/views_ui/src/ViewAddForm.php +++ b/core/modules/views_ui/src/ViewAddForm.php @@ -181,7 +181,7 @@ public function validate(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state) { try { /** @var $wizard \Drupal\views\Plugin\views\wizard\WizardInterface */ $wizard = $form_state['wizard_instance']; diff --git a/core/modules/views_ui/src/ViewDeleteForm.php b/core/modules/views_ui/src/ViewDeleteForm.php index 1acc4b8..4e7e0b0 100644 --- a/core/modules/views_ui/src/ViewDeleteForm.php +++ b/core/modules/views_ui/src/ViewDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\views_ui; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a delete form for a view. */ -class ViewDeleteForm extends EntityConfirmFormBase { +class ViewDeleteForm extends EntityDeleteFormBase { /** * {@inheritdoc} @@ -40,10 +40,9 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function submit(array $form, FormStateInterface $form_state) { - parent::submit($form, $form_state); + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); - $this->entity->delete(); drupal_set_message($this->t('View %name deleted',array('%name' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/views_ui/src/ViewDuplicateForm.php b/core/modules/views_ui/src/ViewDuplicateForm.php index e817e36..3a478c2 100644 --- a/core/modules/views_ui/src/ViewDuplicateForm.php +++ b/core/modules/views_ui/src/ViewDuplicateForm.php @@ -60,6 +60,7 @@ protected function actions(array $form, FormStateInterface $form_state) { '#value' => $this->t('Duplicate'), '#submit' => array( array($this, 'submit'), + array($this, 'save'), ), ); return $actions; @@ -72,11 +73,18 @@ public function submit(array $form, FormStateInterface $form_state) { $original = parent::submit($form, $form_state); $this->entity = $original->createDuplicate(); $this->entity->set('id', $form_state->getValue('id')); - $this->entity->save(); + + return $this->entity; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); // Redirect the user to the view admin form. $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); - return $this->entity; } } diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 6d42b52..2791adb 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -305,8 +305,14 @@ public function submit(array $form, FormStateInterface $form_state) { } } $view->set('display', $displays); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + parent::save($form, $form_state); - // @todo: Revisit this when http://drupal.org/node/1668866 is in. $query = $this->requestStack->getCurrentRequest()->query; $destination = $query->get('destination'); @@ -332,7 +338,6 @@ public function submit(array $form, FormStateInterface $form_state) { $form_state->setRedirectUrl(Url::createFromPath($destination)); } - $view->save(); drupal_set_message($this->t('The view %name has been saved.', array('%name' => $view->label()))); // Remove this view from cache so we can edit it properly.