diff --git a/core/modules/contact/config/install/contact.settings.yml b/core/modules/contact/config/install/contact.settings.yml index 28c760a..f4ae0c2 100644 --- a/core/modules/contact/config/install/contact.settings.yml +++ b/core/modules/contact/config/install/contact.settings.yml @@ -1,4 +1,4 @@ -default_category: feedback +default_form: feedback flood: limit: 5 interval: 3600 diff --git a/core/modules/contact/config/schema/contact.schema.yml b/core/modules/contact/config/schema/contact.schema.yml index 0ef4c2e..7ebb6f4 100644 --- a/core/modules/contact/config/schema/contact.schema.yml +++ b/core/modules/contact/config/schema/contact.schema.yml @@ -1,8 +1,8 @@ # Schema for the configuration files of the Contact module. -contact.category.*: +contact.form.*: type: config_entity - label: 'Contact category' + label: 'Contact form' mapping: id: type: string @@ -27,9 +27,9 @@ contact.settings: type: mapping label: 'Contact settings' mapping: - default_category: + default_form: type: string - label: 'Default category identifier' + label: 'Default form identifier' flood: type: mapping label: 'Flood control' diff --git a/core/modules/contact/contact.info.yml b/core/modules/contact/contact.info.yml index 647bc15..a50d17d 100644 --- a/core/modules/contact/contact.info.yml +++ b/core/modules/contact/contact.info.yml @@ -4,4 +4,4 @@ description: 'Enables the use of both personal and site-wide contact forms.' package: Core version: VERSION core: 8.x -configure: contact.category_list +configure: contact.form_list diff --git a/core/modules/contact/contact.install b/core/modules/contact/contact.install index 477f359..dbe3397 100644 --- a/core/modules/contact/contact.install +++ b/core/modules/contact/contact.install @@ -15,11 +15,11 @@ function contact_install() { if (empty($site_mail)) { $site_mail = ini_get('sendmail_from'); } - $config = \Drupal::config('contact.category.feedback'); + $config = \Drupal::config('contact.form.feedback'); // Update the recipients if the default configuration entity has been created. // We should never rely on default config entities as during enabling a module // during config sync they will not exist. if (!$config->isNew()) { - \Drupal::config('contact.category.feedback')->set('recipients', array($site_mail))->save(); + \Drupal::config('contact.form.feedback')->set('recipients', array($site_mail))->save(); } } diff --git a/core/modules/contact/contact.links.action.yml b/core/modules/contact/contact.links.action.yml index c917e7f..09eaac8 100644 --- a/core/modules/contact/contact.links.action.yml +++ b/core/modules/contact/contact.links.action.yml @@ -1,6 +1,6 @@ -contact.category_add: - route_name: contact.category_add - title: 'Add category' +contact.form_add: + route_name: contact.form_add + title: 'Add form' weight: 1 appears_on: - - contact.category_list + - contact.form_list diff --git a/core/modules/contact/contact.links.task.yml b/core/modules/contact/contact.links.task.yml index e613a83..8259860 100644 --- a/core/modules/contact/contact.links.task.yml +++ b/core/modules/contact/contact.links.task.yml @@ -1,7 +1,7 @@ -contact.category_edit: +contact.form_edit: title: 'Edit' - route_name: contact.category_edit - base_route: contact.category_edit + route_name: contact.form_edit + base_route: contact.form_edit contact.personal_page: title: 'Contact' diff --git a/core/modules/contact/contact.menu_links.yml b/core/modules/contact/contact.menu_links.yml index 683be63..31e5dc7 100644 --- a/core/modules/contact/contact.menu_links.yml +++ b/core/modules/contact/contact.menu_links.yml @@ -1,8 +1,8 @@ -contact.category_list: - title: 'Contact form categories' +contact.form_list: + title: 'Contact forms' parent: system.admin_structure - description: 'Create a system contact form and set up categories for the form to use.' - route_name: contact.category_list + description: 'Create a system contact form and set up other forms to use.' + route_name: contact.form_list contact.site_page: title: Contact route_name: contact.site_page diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index e8485c1..116a683 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -21,7 +21,7 @@ function contact_help($route_name, RouteMatchInterface $route_match) { $output .= '
' . t('User contact forms') . '
'; $output .= '
' . t('Site users can be contacted with a user contact form that keeps their email address private. Users may enable or disable their personal contact forms by editing their My account page. If enabled, a Contact tab leads to a personal contact form displayed on their user profile. Site administrators are still able to use the contact form, even if has been disabled. The Contact tab is not shown when you view your own profile.') . '
'; $output .= '
' . t('Site-wide contact forms') . '
'; - $output .= '
' . t('The Contact page provides a simple form for users with the Use the site-wide contact form permission to send comments, feedback, or other requests. You can create categories for directing the contact form messages to a set of defined recipients. Common categories for a business site, for example, might include "Website feedback" (messages are forwarded to website administrators) and "Product information" (messages are forwarded to members of the sales department). Email addresses defined within a category are not displayed publicly.', array('@contact' => url('contact'))) . '

'; + $output .= '
' . t('The Contact page provides a simple form for users with the Use the site-wide contact form permission to send comments, feedback, or other requests. You can create forms for directing the contact messages to a set of defined recipients. Common forms for a business site, for example, might include "Website feedback" (messages are forwarded to website administrators) and "Product information" (messages are forwarded to members of the sales department). Email addresses defined within a form are not displayed publicly.', array('@contact' => url('contact'))) . '

'; $output .= '
' . t('Navigation') . '
'; $output .= '
' . t('When the site-wide contact form is enabled, a link in the Footer menu is created, which you can modify on the Menus administration page.', array('@menu' => url('admin/structure/menu'))) . '
'; $output .= '
' . t('Customization') . '
'; @@ -29,8 +29,8 @@ function contact_help($route_name, RouteMatchInterface $route_match) { $output .= ''; return $output; - case 'contact.category_list': - $output = '

' . t('Add one or more categories on this page to set up your site-wide contact form.', array('@form' => url('contact'))) . '

'; + case 'contact.form_list': + $output = '

' . t('Add one or more forms on this page to set up your site-wide contact form.', array('@form' => url('contact'))) . '

'; $output .= '

' . t('A Contact menu item is added to the Footer menu, which you can modify on the Menus administration page.', array('@menu-settings' => url('admin/structure/menu'))) . '

'; $output .= '

' . t('If you would like additional text to appear on the site-wide contact page, use a block. You can create and edit blocks on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '

'; return $output; @@ -112,7 +112,7 @@ function contact_mail($key, &$message, $params) { $variables = array( '!site-name' => \Drupal::config('system.site')->get('name'), '!subject' => $contact_message->getSubject(), - '!category' => !empty($params['contact_category']) ? $params['contact_category']->label() : NULL, + '!form' => !empty($params['contact_form']) ? $params['contact_form']->label() : NULL, '!form-url' => url(current_path(), array('absolute' => TRUE, 'language' => $language)), '!sender-name' => user_format_name($sender), ); @@ -128,15 +128,15 @@ function contact_mail($key, &$message, $params) { switch ($key) { case 'page_mail': case 'page_copy': - $message['subject'] .= t('[!category] !subject', $variables, $options); + $message['subject'] .= t('[!form] !subject', $variables, $options); $message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables, $options); $build = entity_view($contact_message, 'mail', $language->id); $message['body'][] = drupal_render($build); break; case 'page_autoreply': - $message['subject'] .= t('[!category] !subject', $variables, $options); - $message['body'][] = $params['contact_category']->reply; + $message['subject'] .= t('[!form] !subject', $variables, $options); + $message['body'][] = $params['contact_form']->reply; break; case 'user_mail': diff --git a/core/modules/contact/contact.routing.yml b/core/modules/contact/contact.routing.yml index 45d800d..ca99c37 100644 --- a/core/modules/contact/contact.routing.yml +++ b/core/modules/contact/contact.routing.yml @@ -1,51 +1,51 @@ -contact.category_delete: - path: '/admin/structure/contact/manage/{contact_category}/delete' +contact.form_delete: + path: '/admin/structure/contact/manage/{contact_form}/delete' defaults: - _entity_form: 'contact_category.delete' + _entity_form: 'contact_form.delete' _title: 'Delete' requirements: - _entity_access: 'contact_category.delete' + _entity_access: 'contact_form.delete' -contact.category_list: +contact.form_list: path: '/admin/structure/contact' defaults: - _entity_list: 'contact_category' - _title: 'Contact form categories' + _entity_list: 'contact_form' + _title: 'Contact forms' requirements: _permission: 'administer contact forms' -contact.category_add: +contact.form_add: path: '/admin/structure/contact/add' defaults: - _entity_form: 'contact_category.add' - _title: 'Add category' + _entity_form: 'contact_form.add' + _title: 'Add form' requirements: _permission: 'administer contact forms' -contact.category_edit: - path: '/admin/structure/contact/manage/{contact_category}' +contact.form_edit: + path: '/admin/structure/contact/manage/{contact_form}' defaults: - _entity_form: 'contact_category.edit' - _title: 'Edit contact category' + _entity_form: 'contact_form.edit' + _title: 'Edit contact form' requirements: - _entity_access: 'contact_category.update' + _entity_access: 'contact_form.update' contact.site_page: path: '/contact' defaults: _title: 'Contact' _content: '\Drupal\contact\Controller\ContactController::contactSitePage' - contact_category: NULL + contact_form: NULL requirements: _permission: 'access site-wide contact form' -contact.site_page_category: - path: '/contact/{contact_category}' +contact.site_page_form: + path: '/contact/{contact_form}' defaults: - _title: 'Contact category form' + _title: 'Contact form' _content: '\Drupal\contact\Controller\ContactController::contactSitePage' requirements: - _entity_access: 'contact_category.view' + _entity_access: 'contact_form.view' contact.personal_page: path: '/user/{user}/contact' diff --git a/core/modules/contact/src/CategoryAccessController.php b/core/modules/contact/src/CategoryAccessController.php deleted file mode 100644 index f798d79..0000000 --- a/core/modules/contact/src/CategoryAccessController.php +++ /dev/null @@ -1,38 +0,0 @@ -hasPermission('access site-wide contact form') && $entity->id() !== 'personal'; - } - elseif ($operation == 'delete' || $operation == 'update') { - // Do not allow the 'personal' category to be deleted, as it's used for - // the personal contact form. - return $account->hasPermission('administer contact forms') && $entity->id() !== 'personal'; - } - - return parent::checkAccess($entity, $operation, $langcode, $account); - } - -} diff --git a/core/modules/contact/src/CategoryForm.php b/core/modules/contact/src/CategoryForm.php deleted file mode 100644 index 73fce38..0000000 --- a/core/modules/contact/src/CategoryForm.php +++ /dev/null @@ -1,125 +0,0 @@ -entity; - $default_category = \Drupal::config('contact.settings')->get('default_category'); - - $form['label'] = array( - '#type' => 'textfield', - '#title' => t('Label'), - '#maxlength' => 255, - '#default_value' => $category->label(), - '#description' => t("Example: 'website feedback' or 'product information'."), - '#required' => TRUE, - ); - $form['id'] = array( - '#type' => 'machine_name', - '#default_value' => $category->id(), - '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, - '#machine_name' => array( - 'exists' => '\Drupal\contact\Entity\Category::load', - ), - '#disabled' => !$category->isNew(), - ); - $form['recipients'] = array( - '#type' => 'textarea', - '#title' => t('Recipients'), - '#default_value' => implode(', ', $category->recipients), - '#description' => t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com' . To specify multiple recipients, separate each email address with a comma."), - '#required' => TRUE, - ); - $form['reply'] = array( - '#type' => 'textarea', - '#title' => t('Auto-reply'), - '#default_value' => $category->reply, - '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'), - ); - $form['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight'), - '#default_value' => $category->weight, - '#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'), - ); - $form['selected'] = array( - '#type' => 'checkbox', - '#title' => t('Make this the default category.'), - '#default_value' => $default_category === $category->id(), - ); - - return $form; - } - - /** - * Overrides Drupal\Core\Entity\EntityForm::validate(). - */ - public function validate(array $form, array &$form_state) { - parent::validate($form, $form_state); - - // Validate and each email recipient. - $recipients = explode(',', $form_state['values']['recipients']); - - foreach ($recipients as &$recipient) { - $recipient = trim($recipient); - if (!valid_email_address($recipient)) { - $this->setFormError('recipients', $form_state, $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient))); - } - } - $form_state['values']['recipients'] = $recipients; - } - - /** - * Overrides Drupal\Core\Entity\EntityForm::save(). - */ - public function save(array $form, array &$form_state) { - $category = $this->entity; - $status = $category->save(); - - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); - - if ($status == SAVED_UPDATED) { - drupal_set_message(t('Category %label has been updated.', array('%label' => $category->label()))); - watchdog('contact', 'Category %label has been updated.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link); - } - else { - drupal_set_message(t('Category %label has been added.', array('%label' => $category->label()))); - watchdog('contact', 'Category %label has been added.', array('%label' => $category->label()), WATCHDOG_NOTICE, $edit_link); - } - - // Update the default category. - $contact_config = \Drupal::config('contact.settings'); - if ($form_state['values']['selected']) { - $contact_config - ->set('default_category', $category->id()) - ->save(); - } - // If it was the default category, empty out the setting. - elseif ($contact_config->get('default_category') == $category->id()) { - $contact_config - ->set('default_category', NULL) - ->save(); - } - - $form_state['redirect_route']['route_name'] = 'contact.category_list'; - } - -} diff --git a/core/modules/contact/src/CategoryInterface.php b/core/modules/contact/src/CategoryInterface.php deleted file mode 100644 index 0f3dd5b..0000000 --- a/core/modules/contact/src/CategoryInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -getLabel($entity); - // Special case the personal category. - if ($entity->id() == 'personal') { - $row['recipients'] = t('Selected user'); - $row['selected'] = t('No'); - } - else { - $row['recipients'] = String::checkPlain(implode(', ', $entity->recipients)); - $default_category = \Drupal::config('contact.settings')->get('default_category'); - $row['selected'] = ($default_category == $entity->id() ? t('Yes') : t('No')); - } - return $row + parent::buildRow($entity); - } - -} diff --git a/core/modules/contact/src/ContactForm.php b/core/modules/contact/src/ContactForm.php new file mode 100644 index 0000000..a2710c8 --- /dev/null +++ b/core/modules/contact/src/ContactForm.php @@ -0,0 +1,125 @@ +entity; + $default_form = \Drupal::config('contact.settings')->get('default_form'); + + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Label'), + '#maxlength' => 255, + '#default_value' => $contact_form->label(), + '#description' => t("Example: 'website feedback' or 'product information'."), + '#required' => TRUE, + ); + $form['id'] = array( + '#type' => 'machine_name', + '#default_value' => $contact_form->id(), + '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, + '#machine_name' => array( + 'exists' => '\Drupal\contact\Entity\ContactForm::load', + ), + '#disabled' => !$contact_form->isNew(), + ); + $form['recipients'] = array( + '#type' => 'textarea', + '#title' => t('Recipients'), + '#default_value' => implode(', ', $contact_form->recipients), + '#description' => t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com' . To specify multiple recipients, separate each email address with a comma."), + '#required' => TRUE, + ); + $form['reply'] = array( + '#type' => 'textarea', + '#title' => t('Auto-reply'), + '#default_value' => $contact_form->reply, + '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'), + ); + $form['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight'), + '#default_value' => $contact_form->weight, + '#description' => t('When listing forms, those with lighter (smaller) weights get listed before forms with heavier (larger) weights. Forms with equal weights are sorted alphabetically.'), + ); + $form['selected'] = array( + '#type' => 'checkbox', + '#title' => t('Make this the default form.'), + '#default_value' => $default_form === $contact_form->id(), + ); + + return $form; + } + + /** + * Overrides Drupal\Core\Entity\EntityForm::validate(). + */ + public function validate(array $form, array &$form_state) { + parent::validate($form, $form_state); + + // Validate and each email recipient. + $recipients = explode(',', $form_state['values']['recipients']); + + foreach ($recipients as &$recipient) { + $recipient = trim($recipient); + if (!valid_email_address($recipient)) { + $this->setFormError('recipients', $form_state, $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient))); + } + } + $form_state['values']['recipients'] = $recipients; + } + + /** + * Overrides Drupal\Core\Entity\EntityForm::save(). + */ + public function save(array $form, array &$form_state) { + $contact_form = $this->entity; + $status = $contact_form->save(); + + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + + if ($status == SAVED_UPDATED) { + drupal_set_message(t('Form %label has been updated.', array('%label' => $contact_form->label()))); + watchdog('contact', 'Form %label has been updated.', array('%label' => $contact_form->label()), WATCHDOG_NOTICE, $edit_link); + } + else { + drupal_set_message(t('Form %label has been added.', array('%label' => $contact_form->label()))); + watchdog('contact', 'Form %label has been added.', array('%label' => $contact_form->label()), WATCHDOG_NOTICE, $edit_link); + } + + // Update the default form. + $contact_config = \Drupal::config('contact.settings'); + if ($form_state['values']['selected']) { + $contact_config + ->set('default_form', $contact_form->id()) + ->save(); + } + // If it was the default form, empty out the setting. + elseif ($contact_config->get('default_form') == $contact_form->id()) { + $contact_config + ->set('default_form', NULL) + ->save(); + } + + $form_state['redirect_route']['route_name'] = 'contact.form_list'; + } + +} diff --git a/core/modules/contact/src/ContactFormAccessController.php b/core/modules/contact/src/ContactFormAccessController.php new file mode 100644 index 0000000..00516e5 --- /dev/null +++ b/core/modules/contact/src/ContactFormAccessController.php @@ -0,0 +1,38 @@ +hasPermission('access site-wide contact form') && $entity->id() !== 'personal'; + } + elseif ($operation == 'delete' || $operation == 'update') { + // Do not allow the 'personal' form to be deleted, as it's used for + // the personal contact form. + return $account->hasPermission('administer contact forms') && $entity->id() !== 'personal'; + } + + return parent::checkAccess($entity, $operation, $langcode, $account); + } + +} diff --git a/core/modules/contact/src/ContactFormInterface.php b/core/modules/contact/src/ContactFormInterface.php new file mode 100644 index 0000000..cda8e27 --- /dev/null +++ b/core/modules/contact/src/ContactFormInterface.php @@ -0,0 +1,17 @@ +getLabel($entity); + // Special case the personal form. + if ($entity->id() == 'personal') { + $row['recipients'] = t('Selected user'); + $row['selected'] = t('No'); + } + else { + $row['recipients'] = String::checkPlain(implode(', ', $entity->recipients)); + $default_form = \Drupal::config('contact.settings')->get('default_form'); + $row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No')); + } + return $row + parent::buildRow($entity); + } + +} diff --git a/core/modules/contact/src/Controller/ContactController.php b/core/modules/contact/src/Controller/ContactController.php index df720bc..61a5ccd 100644 --- a/core/modules/contact/src/Controller/ContactController.php +++ b/core/modules/contact/src/Controller/ContactController.php @@ -9,7 +9,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Flood\FloodInterface; -use Drupal\contact\CategoryInterface; +use Drupal\contact\ContactFormInterface; use Drupal\user\UserInterface; use Drupal\Component\Utility\String; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -50,32 +50,32 @@ public static function create(ContainerInterface $container) { /** * Presents the site-wide contact form. * - * @param \Drupal\contact\CategoryInterface $contact_category - * The contact category to use. + * @param \Drupal\contact\ContactFormInterface $contact_form + * The contact form to use. * * @return array * The form as render array as expected by drupal_render(). * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * Exception is thrown when user tries to access non existing default - * contact category form. + * contact form. */ - public function contactSitePage(CategoryInterface $contact_category = NULL) { + public function contactSitePage(ContactFormInterface $contact_form = NULL) { // Check if flood control has been activated for sending emails. if (!$this->currentUser()->hasPermission('administer contact forms')) { $this->contactFloodControl(); } - // Use the default category if no category has been passed. - if (empty($contact_category)) { - $contact_category = $this->entityManager() - ->getStorage('contact_category') - ->load($this->config('contact.settings')->get('default_category')); - // If there are no categories, do not display the form. - if (empty($contact_category)) { + // Use the default form if no form has been passed. + if (empty($contact_form)) { + $contact_form = $this->entityManager() + ->getStorage('contact_form') + ->load($this->config('contact.settings')->get('default_form')); + // If there are no forms, do not display the form. + if (empty($contact_form)) { if ($this->currentUser()->hasPermission('administer contact forms')) { - drupal_set_message($this->t('The contact form has not been configured. Add one or more categories to the form.', array( - '@add' => $this->url('contact.category_add'))), 'error'); + drupal_set_message($this->t('The contact form has not been configured. Add one or more form .', array( + '@add' => $this->url('contact.form_add'))), 'error'); return array(); } else { @@ -87,11 +87,11 @@ public function contactSitePage(CategoryInterface $contact_category = NULL) { $message = $this->entityManager() ->getStorage('contact_message') ->create(array( - 'category' => $contact_category->id(), + 'contact_form' => $contact_form->id(), )); $form = $this->entityFormBuilder()->getForm($message); - $form['#title'] = String::checkPlain($contact_category->label()); + $form['#title'] = String::checkPlain($contact_form->label()); return $form; } @@ -111,7 +111,7 @@ public function contactPersonalPage(UserInterface $user) { } $message = $this->entityManager()->getStorage('contact_message')->create(array( - 'category' => 'personal', + 'contact_form' => 'personal', 'recipient' => $user->id(), )); diff --git a/core/modules/contact/src/Entity/Category.php b/core/modules/contact/src/Entity/Category.php deleted file mode 100644 index cc0e6d8..0000000 --- a/core/modules/contact/src/Entity/Category.php +++ /dev/null @@ -1,80 +0,0 @@ -get('category')->entity; + public function getContactForm() { + return $this->get('contact_form')->entity; } /** @@ -135,10 +135,10 @@ public function getPersonalRecipient() { * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields['category'] = FieldDefinition::create('entity_reference') - ->setLabel(t('Category ID')) - ->setDescription(t('The ID of the associated category.')) - ->setSetting('target_type', 'contact_category') + $fields['contact_form'] = FieldDefinition::create('entity_reference') + ->setLabel(t('Form ID')) + ->setDescription(t('The ID of the associated form.')) + ->setSetting('target_type', 'contact_form') ->setRequired(TRUE); $fields['uuid'] = FieldDefinition::create('uuid') diff --git a/core/modules/contact/src/Form/CategoryDeleteForm.php b/core/modules/contact/src/Form/CategoryDeleteForm.php deleted file mode 100644 index 799513a..0000000 --- a/core/modules/contact/src/Form/CategoryDeleteForm.php +++ /dev/null @@ -1,49 +0,0 @@ - $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelRoute() { - return new Url('contact.category_list'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submit(array $form, array &$form_state) { - $this->entity->delete(); - drupal_set_message(t('Category %label has been deleted.', array('%label' => $this->entity->label()))); - watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE); - $form_state['redirect_route'] = $this->getCancelRoute(); - } - -} diff --git a/core/modules/contact/src/Form/ContactFormDeleteForm.php b/core/modules/contact/src/Form/ContactFormDeleteForm.php new file mode 100644 index 0000000..4838c1d --- /dev/null +++ b/core/modules/contact/src/Form/ContactFormDeleteForm.php @@ -0,0 +1,49 @@ + $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { + return new Url('contact.form_list'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->delete(); + drupal_set_message(t('Form %label has been deleted.', array('%label' => $this->entity->label()))); + watchdog('contact', 'Form %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE); + $form_state['redirect_route'] = $this->getCancelRoute(); + } + +} diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php index 6bf5e91..9715e3e 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -86,7 +86,7 @@ public function form(array $form, array &$form_state) { $form['preview']['message'] = $this->entityManager->getViewBuilder('contact_message')->view($message, 'full'); } - $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('contact_message', $message->getCategory()->id())); + $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('contact_message', $message->getContactForm()->id())); $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', @@ -203,11 +203,11 @@ public function save(array $form, array &$form_state) { $params['sender'] = $sender; if (!$message->isPersonal()) { - // Send to the category recipient(s), using the site's default language. - $category = $message->getCategory(); - $params['contact_category'] = $category; + // Send to the form recipient(s), using the site's default language. + $contact_form = $message->getContactForm(); + $params['contact_form'] = $contact_form; - $to = implode(', ', $category->recipients); + $to = implode(', ', $contact_form->recipients); $recipient_langcode = $this->languageManager->getDefaultLanguage()->getId(); } elseif ($recipient = $message->getPersonalRecipient()) { @@ -230,7 +230,7 @@ public function save(array $form, array &$form_state) { } // If configured, send an auto-reply, using the current language. - if (!$message->isPersonal() && $category->reply) { + if (!$message->isPersonal() && $contact_form->reply) { // User contact forms do not support an auto-reply message, so this // message always originates from the site. drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params); @@ -239,10 +239,10 @@ public function save(array $form, array &$form_state) { $config = $this->config('contact.settings'); $this->flood->register('contact', $config->get('flood.interval')); if (!$message->isPersonal()) { - watchdog('contact', '%sender-name (@sender-from) sent an email regarding %category.', array( + watchdog('contact', '%sender-name (@sender-from) sent an email regarding %form.', array( '%sender-name' => $sender->getUsername(), '@sender-from' => $sender->getEmail(), - '%category' => $category->label(), + '%form' => $contact_form->label(), )); } else { diff --git a/core/modules/contact/src/MessageInterface.php b/core/modules/contact/src/MessageInterface.php index b73bd2d..85318ec 100644 --- a/core/modules/contact/src/MessageInterface.php +++ b/core/modules/contact/src/MessageInterface.php @@ -15,12 +15,12 @@ interface MessageInterface extends ContentEntityInterface { /** - * Returns the category this contact message belongs to. + * Returns the form this contact message belongs to. * - * @return \Drupal\contact\CategoryInterface - * The contact category entity. + * @return \Drupal\contact\ContactFormInterface + * The contact form entity. */ - public function getCategory(); + public function getContactForm(); /** * Returns the name of the sender. diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index 2be4208..992b714 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -52,9 +52,9 @@ function testSiteWideContact() { $this->assertText(t('The configuration options have been saved.')); $this->drupalGet('admin/structure/contact'); - // Default category exists. + // Default form exists. $this->assertLinkByHref('admin/structure/contact/manage/feedback/delete'); - // User category could not be changed or deleted. + // User form could not be changed or deleted. // Cannot use ::assertNoLinkByHref as it does partial url matching and with // field_ui enabled admin/structure/contact/manage/personal/fields exists. // @todo: See https://drupal.org/node/2031223 for the above @@ -69,13 +69,13 @@ function testSiteWideContact() { $this->drupalGet('admin/structure/contact/manage/personal'); $this->assertResponse(403); - // Delete old categories to ensure that new categories are used. - $this->deleteCategories(); + // Delete old forms to ensure that new forms are used. + $this->deleteContactForms(); $this->drupalGet('admin/structure/contact'); - $this->assertText('Personal', 'Personal category was not deleted'); + $this->assertText('Personal', 'Personal form was not deleted'); $this->assertNoLinkByHref('admin/structure/contact/manage/feedback'); - // Ensure that the contact form won't be shown without categories. + // Ensure that the contact form won't be shown without forms. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); @@ -85,20 +85,20 @@ function testSiteWideContact() { $this->drupalGet('contact'); $this->assertResponse(200); $this->assertText(t('The contact form has not been configured.')); - // Test access personal category via site-wide contact page. + // Test access personal form via site-wide contact page. $this->drupalGet('contact/personal'); $this->assertResponse(403); - // Add categories. + // Add forms. // Test invalid recipients. $invalid_recipients = array('invalid', 'invalid@', 'invalid@site.', '@site.', '@site.com'); foreach ($invalid_recipients as $invalid_recipient) { - $this->addCategory($this->randomName(16), $this->randomName(16), $invalid_recipient, '', FALSE); + $this->addContactForm($this->randomName(16), $this->randomName(16), $invalid_recipient, '', FALSE); $this->assertRaw(t('%recipient is an invalid email address.', array('%recipient' => $invalid_recipient))); } - // Test validation of empty category and recipients fields. - $this->addCategory('', '', '', '', TRUE); + // Test validation of empty form and recipients fields. + $this->addContactForm('', '', '', '', TRUE); $this->assertText(t('Label field is required.')); $this->assertText(t('Machine-readable name field is required.')); $this->assertText(t('Recipients field is required.')); @@ -107,56 +107,56 @@ function testSiteWideContact() { $recipients = array('simpletest@example.com', 'simpletest2@example.com', 'simpletest3@example.com'); $max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH; $max_length_exceeded = $max_length + 1; - $this->addCategory($id = drupal_strtolower($this->randomName($max_length_exceeded)), $label = $this->randomName($max_length_exceeded), implode(',', array($recipients[0])), '', TRUE); + $this->addContactForm($id = drupal_strtolower($this->randomName($max_length_exceeded)), $label = $this->randomName($max_length_exceeded), implode(',', array($recipients[0])), '', TRUE); $this->assertText(format_string('Machine-readable name cannot be longer than !max characters but is currently !exceeded characters long.', array('!max' => $max_length, '!exceeded' => $max_length_exceeded))); - $this->addCategory($id = drupal_strtolower($this->randomName($max_length)), $label = $this->randomName($max_length), implode(',', array($recipients[0])), '', TRUE); - $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); + $this->addContactForm($id = drupal_strtolower($this->randomName($max_length)), $label = $this->randomName($max_length), implode(',', array($recipients[0])), '', TRUE); + $this->assertRaw(t('Form %label has been added.', array('%label' => $label))); - // Create first valid category. - $this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE); - $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); + // Create first valid form. + $this->addContactForm($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE); + $this->assertRaw(t('Form %label has been added.', array('%label' => $label))); - // Check that the category was created in site default language. - $langcode = \Drupal::config('contact.category.' . $id)->get('langcode'); + // Check that the form was created in site default language. + $langcode = \Drupal::config('contact.form.' . $id)->get('langcode'); $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id; $this->assertEqual($langcode, $default_langcode); - // Make sure the newly created category is included in the list of categories. - $this->assertNoUniqueText($label, 'New category included in categories list.'); + // Make sure the newly created form is included in the list of forms. + $this->assertNoUniqueText($label, 'New form included in forms list.'); - // Test update contact form category. - $this->updateCategory($id, $label = $this->randomName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); - $config = \Drupal::config('contact.category.' . $id)->get(); + // Test update contact form. + $this->updateContactForm($id, $label = $this->randomName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); + $config = \Drupal::config('contact.form.' . $id)->get(); $this->assertEqual($config['label'], $label); $this->assertEqual($config['recipients'], array($recipients[0], $recipients[1])); $this->assertEqual($config['reply'], $reply); - $this->assertNotEqual($id, \Drupal::config('contact.settings')->get('default_category')); - $this->assertRaw(t('Category %label has been updated.', array('%label' => $label))); - // Ensure the label is displayed on the contact page for this category. + $this->assertNotEqual($id, \Drupal::config('contact.settings')->get('default_form')); + $this->assertRaw(t('Form %label has been updated.', array('%label' => $label))); + // Ensure the label is displayed on the contact page for this form. $this->drupalGet('contact/' . $id); $this->assertText($label); - // Reset the category back to be the default category. - \Drupal::config('contact.settings')->set('default_category', $id)->save(); + // Reset the form back to be the default form. + \Drupal::config('contact.settings')->set('default_form', $id)->save(); - // Ensure that the contact form is shown without a category selection input. + // Ensure that the contact form is shown without a form selection input. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); - $this->assertNoText(t('Category')); + $this->assertNoText(t('Form')); $this->drupalLogin($admin_user); - // Add more categories. - $this->addCategory(drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE); - $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); + // Add more forms. + $this->addContactForm(drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE); + $this->assertRaw(t('Form %label has been added.', array('%label' => $label))); - $this->addCategory($name = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE); - $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); + $this->addContactForm($name = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE); + $this->assertRaw(t('Form %label has been added.', array('%label' => $label))); - // Try adding a category that already exists. - $this->addCategory($name, $label, '', '', FALSE); - $this->assertNoRaw(t('Category %label has been saved.', array('%label' => $label))); + // Try adding a form that already exists. + $this->addContactForm($name, $label, '', '', FALSE); + $this->assertNoRaw(t('Form %label has been saved.', array('%label' => $label))); $this->assertRaw(t('The machine-readable name is already in use. It must be unique.')); // Clear flood table in preparation for flood test and allow other checks to complete. @@ -191,14 +191,14 @@ function testSiteWideContact() { $this->submitContact($this->randomName(16), $recipients[0], $this->randomName(16), $id, ''); $this->assertText(t('Message field is required.')); - // Test contact form with no default category selected. + // Test contact form with no default form selected. \Drupal::config('contact.settings') - ->set('default_category', '') + ->set('default_form', '') ->save(); $this->drupalGet('contact'); $this->assertResponse(404); - // Try to access contact form with non-existing category IDs. + // Try to access contact form with non-existing form IDs. $this->drupalGet('contact/0'); $this->assertResponse(404); $this->drupalGet('contact/' . $this->randomName()); @@ -217,12 +217,12 @@ function testSiteWideContact() { // Test listing controller. $this->drupalLogin($admin_user); - $this->deleteCategories(); + $this->deleteContactForms(); $label = $this->randomName(16); $recipients = implode(',', array($recipients[0], $recipients[1], $recipients[2])); - $category = drupal_strtolower($this->randomName(16)); - $this->addCategory($category, $label, $recipients, '', FALSE); + $contact_form = drupal_strtolower($this->randomName(16)); + $this->addContactForm($contact_form, $label, $recipients, '', FALSE); $this->drupalGet('admin/structure/contact'); $this->clickLink(t('Edit')); $this->assertResponse(200); @@ -231,7 +231,7 @@ function testSiteWideContact() { // Test field UI and field integration. $this->drupalGet('admin/structure/contact'); - // Find out in which row the category we want to add a field to is. + // Find out in which row the form we want to add a field to is. $i = 0; foreach($this->xpath('//table/tbody/tr') as $row) { if (((string)$row->td[0]) == $label) { @@ -255,7 +255,7 @@ function testSiteWideContact() { $this->drupalPostForm(NULL, array(), t('Save settings')); // Check that the field is displayed. - $this->drupalGet('contact/' . $category); + $this->drupalGet('contact/' . $contact_form); $this->assertText($field_label); // Submit the contact form and verify the content. @@ -280,18 +280,18 @@ function testAutoReply() { $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer permissions', 'administer users')); $this->drupalLogin($admin_user); - // Set up three categories, 2 with an auto-reply and one without. + // Set up three forms, 2 with an auto-reply and one without. $foo_autoreply = $this->randomName(40); $bar_autoreply = $this->randomName(40); - $this->addCategory('foo', 'foo', 'foo@example.com', $foo_autoreply, FALSE); - $this->addCategory('bar', 'bar', 'bar@example.com', $bar_autoreply, FALSE); - $this->addCategory('no_autoreply', 'no_autoreply', 'bar@example.com', '', FALSE); + $this->addContactForm('foo', 'foo', 'foo@example.com', $foo_autoreply, FALSE); + $this->addContactForm('bar', 'bar', 'bar@example.com', $bar_autoreply, FALSE); + $this->addContactForm('no_autoreply', 'no_autoreply', 'bar@example.com', '', FALSE); // Log the current user out in order to test the name and email fields. $this->drupalLogout(); user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); - // Test the auto-reply for category 'foo'. + // Test the auto-reply for form 'foo'. $email = $this->randomName(32) . '@example.com'; $subject = $this->randomName(64); $this->submitContact($this->randomName(16), $email, $subject, 'foo', $this->randomString(128)); @@ -301,11 +301,11 @@ function testAutoReply() { $this->assertEqual(count($captured_emails), 1); $this->assertEqual(trim($captured_emails[0]['body']), trim(drupal_html_to_text($foo_autoreply))); - // Test the auto-reply for category 'bar'. + // Test the auto-reply for form 'bar'. $email = $this->randomName(32) . '@example.com'; $this->submitContact($this->randomName(16), $email, $this->randomString(64), 'bar', $this->randomString(128)); - // Auto-reply for category 'bar' should result in one auto-reply email to the sender. + // Auto-reply for form 'bar' should result in one auto-reply email to the sender. $captured_emails = $this->drupalGetMails(array('id' => 'contact_page_autoreply', 'to' => $email)); $this->assertEqual(count($captured_emails), 1); $this->assertEqual(trim($captured_emails[0]['body']), trim(drupal_html_to_text($bar_autoreply))); @@ -318,21 +318,21 @@ function testAutoReply() { } /** - * Adds a category. + * Adds a form. * * @param string $id - * The category machine name. + * The form machine name. * @param string $label - * The category label. + * The form label. * @param string $recipients * The list of recipient email addresses. * @param string $reply * The auto-reply text that is sent to a user upon completing the contact * form. * @param boolean $selected - * A Boolean indicating whether the category should be selected by default. + * A Boolean indicating whether the form should be selected by default. */ - function addCategory($id, $label, $recipients, $reply, $selected) { + function addContactForm($id, $label, $recipients, $reply, $selected) { $edit = array(); $edit['label'] = $label; $edit['id'] = $id; @@ -343,21 +343,21 @@ function addCategory($id, $label, $recipients, $reply, $selected) { } /** - * Updates a category. + * Updates a form. * * @param string $id - * The category machine name. + * The form machine name. * @param string $label - * The category label. + * The form label. * @param string $recipients * The list of recipient email addresses. * @param string $reply * The auto-reply text that is sent to a user upon completing the contact * form. * @param boolean $selected - * A Boolean indicating whether the category should be selected by default. + * A Boolean indicating whether the form should be selected by default. */ - function updateCategory($id, $label, $recipients, $reply, $selected) { + function updateContactForm($id, $label, $recipients, $reply, $selected) { $edit = array(); $edit['label'] = $label; $edit['recipients'] = $recipients; @@ -376,7 +376,7 @@ function updateCategory($id, $label, $recipients, $reply, $selected) { * @param string $subject * The subject of the message. * @param string $id - * The category ID of the message. + * The form ID of the message. * @param string $message * The message body. */ @@ -386,7 +386,7 @@ function submitContact($name, $mail, $subject, $id, $message) { $edit['mail'] = $mail; $edit['subject[0][value]'] = $subject; $edit['message[0][value]'] = $message; - if ($id == \Drupal::config('contact.settings')->get('default_category')) { + if ($id == \Drupal::config('contact.settings')->get('default_form')) { $this->drupalPostForm('contact', $edit, t('Send message')); } else { @@ -395,20 +395,20 @@ function submitContact($name, $mail, $subject, $id, $message) { } /** - * Deletes all categories. + * Deletes all forms. */ - function deleteCategories() { - $categories = entity_load_multiple('contact_category'); - foreach ($categories as $id => $category) { + function deleteContactForms() { + $contact_fors = entity_load_multiple('contact_form'); + foreach ($contact_forms as $id => $contact_form) { if ($id == 'personal') { - // Personal category could not be deleted. + // Personal form could not be deleted. $this->drupalGet("admin/structure/contact/manage/$id/delete"); $this->assertResponse(403); } else { $this->drupalPostForm("admin/structure/contact/manage/$id/delete", array(), t('Delete')); - $this->assertRaw(t('Category %label has been deleted.', array('%label' => $category->label()))); - $this->assertFalse(entity_load('contact_category', $id), format_string('Category %category not found', array('%category' => $category->label()))); + $this->assertRaw(t('Form %label has been deleted.', array('%label' => $contact_form->label()))); + $this->assertFalse(entity_load('contact_form', $id), format_string('Form %contact_form not found', array('%contact_form' => $contact_form->label()))); } } } diff --git a/core/modules/contact/src/Tests/ContactStorageTest.php b/core/modules/contact/src/Tests/ContactStorageTest.php index c5784a7..ebfdfba 100644 --- a/core/modules/contact/src/Tests/ContactStorageTest.php +++ b/core/modules/contact/src/Tests/ContactStorageTest.php @@ -47,24 +47,24 @@ public function testContactStorage() { 'administer contact_message fields', )); $this->drupalLogin($admin_user); - // Create first valid category. + // Create first valid contact form. $mail = 'simpletest@example.com'; - $this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($mail)), '', TRUE); - $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); + $this->addContactForm($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($mail)), '', TRUE); + $this->assertRaw(t('Form %label has been added.', array('%label' => $label))); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); - $this->assertNoText(t('Category')); + $this->assertNoText(t('Form')); $this->submitContact($name = $this->randomName(16), $mail, $subject = $this->randomName(16), $id, $message = $this->randomName(64)); $this->assertText(t('Your message has been sent.')); $messages = Message::loadMultiple(); /** @var \Drupal\contact\Entity\Message $message */ $message = reset($messages); - $this->assertEqual($message->getCategory()->id(), $id); + $this->assertEqual($message->getContactForm()->id(), $id); $this->assertEqual($message->getSenderName(), $name); $this->assertEqual($message->getSubject(), $subject); $this->assertEqual($message->getSenderMail(), $mail); diff --git a/core/modules/contact/src/Tests/MessageEntityTest.php b/core/modules/contact/src/Tests/MessageEntityTest.php index e27d23c..29618b7 100644 --- a/core/modules/contact/src/Tests/MessageEntityTest.php +++ b/core/modules/contact/src/Tests/MessageEntityTest.php @@ -34,7 +34,7 @@ protected function setUp() { */ public function testMessageMethods() { $message_storage = $this->container->get('entity.manager')->getStorage('contact_message'); - $message = $message_storage->create(array('category' => 'feedback')); + $message = $message_storage->create(array('contact_form' => 'feedback')); // Check for empty values first. $this->assertEqual($message->getMessage(), ''); @@ -43,7 +43,7 @@ public function testMessageMethods() { $this->assertFalse($message->copySender()); // Check for default values. - $this->assertEqual('feedback', $message->getCategory()->id()); + $this->assertEqual('feedback', $message->getContactForm()->id()); $this->assertFalse($message->isPersonal()); // Set some values and check for them afterwards. diff --git a/core/modules/contact/src/Tests/Views/ContactFieldsTest.php b/core/modules/contact/src/Tests/Views/ContactFieldsTest.php index e6e70ad..ffad26a 100644 --- a/core/modules/contact/src/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/src/Tests/Views/ContactFieldsTest.php @@ -41,9 +41,9 @@ protected function setUp() { )); $this->field->save(); - entity_create('contact_category', array( + entity_create('contact_form', array( 'id' => 'contact_message', - 'label' => 'Test contact category', + 'label' => 'Test contact form', ))->save(); entity_create('field_instance_config', array( diff --git a/core/modules/contact/tests/drupal-7.contact.database.php b/core/modules/contact/tests/drupal-7.contact.database.php index ed8e5ba..7d67461 100644 --- a/core/modules/contact/tests/drupal-7.contact.database.php +++ b/core/modules/contact/tests/drupal-7.contact.database.php @@ -9,22 +9,22 @@ * the database structure expected in tests altogether. */ -// Update the default category to that it is not selected. +// Update the default form to that it is not selected. db_update('contact') ->fields(array('selected' => '0')) ->condition('cid', '1') ->execute(); -// Add a custom contact category. +// Add a custom contact form. db_insert('contact')->fields(array( - 'category', + 'contact_form', 'recipients', 'reply', 'weight', 'selected' )) ->values(array( - 'category' => 'Upgrade test', + 'contact_form' => 'Upgrade test', 'recipients'=> 'test1@example.com,test2@example.com', 'reply' => 'Test reply', 'weight' => 1,