diff --git a/core/modules/contact/lib/Drupal/contact/CategoryListController.php b/core/modules/contact/lib/Drupal/contact/CategoryListController.php index 286db21..8dcdf3b 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryListController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryListController.php @@ -9,6 +9,10 @@ use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormInterface; +use Drupal\Core\Config\ConfigFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\contact\CategoryStorageController; /** * Provides a listing of contact categories. @@ -16,6 +20,53 @@ class CategoryListController extends ConfigEntityListController implements FormInterface { /** + * Stores the configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * Stores the default category. + * + * @var string + */ + protected $defaultCategory; + + /** + * Constructs a new CategoryListController. + * + * @param string $entity_type + * The type of entity to be listed. + * @param array $entity_info + * An array of entity info for the entity type. + * @param \Drupal\contact\CategoryStorageController $storage + * The contact category storage controller class. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke hooks on. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + */ + public function __construct($entity_type, array $entity_info, CategoryStorageController $storage, ModuleHandlerInterface $module_handler, ConfigFactory $config_factory) { + parent::__construct($entity_type, $entity_info, $storage, $module_handler); + $this->configFactory = $config_factory; + $this->defaultCategory = $config_factory->get('contact.settings'); + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $entity_type, + $entity_info, + $container->get('plugin.manager.entity')->getStorageController($entity_type), + $container->get('module_handler'), + $container->get('config.factory') + ); + } + + /** * {@inheritdoc} */ public function getFormID() { @@ -74,8 +125,7 @@ public function buildRow(EntityInterface $entity) { } else { $row['recipients'] = check_plain(implode(', ', $entity->recipients)); - $default_category = config('contact.settings')->get('default_category'); - $row['default'] = ($default_category == $entity->id() ? t('Yes') : t('No')); + $row['default'] = ($this->defaultCategory == $entity->id() ? t('Yes') : t('No')); } $row['operations']['data'] = $this->buildOperations($entity); return $row; @@ -106,7 +156,6 @@ public function buildForm(array $form, array &$form_state) { array('order', 'sibling', 'weight'), ), ); - $default_category = config('contact.settings')->get('default_category'); foreach ($this->load() as $entity) { $row = $this->buildRow($entity); // Override default values to markup elements. @@ -126,7 +175,7 @@ public function buildForm(array $form, array &$form_state) { '#title' => t('Set @title as default', array('@title' => $entity->label())), '#title_display' => 'invisible', '#return_value' => $entity->id(), - '#default_value' => ($default_category == $entity->id() ? $entity->id() : NULL), + '#default_value' => ($this->defaultCategory == $entity->id() ? $entity->id() : NULL), '#parents' => array('default_category'), '#id' => 'edit-entities-default', // Personal category could not be set default. @@ -169,7 +218,7 @@ public function validateForm(array &$form, array &$form_state) { public function submitForm(array &$form, array &$form_state) { $values = $form_state['values']['entities']; - $entities = entity_load_multiple($this->entityType, array_keys($values)); + $entities = $this->storage->loadMultiple(array_keys($values)); foreach ($values as $id => $value) { if (isset($entities[$id]) && $value['weight'] != $entities[$id]->get('weight')) { // Update changed weight. @@ -178,10 +227,9 @@ public function submitForm(array &$form, array &$form_state) { } } // Update the site's default contact category. - $contact_config = config('contact.settings'); $default_category = $form_state['values']['default_category']; - if (isset($entities[$default_category]) && $default_category != $contact_config->get('default_category')) { - $contact_config + if (isset($entities[$default_category]) && $default_category != $this->defaultCategory) { + $this->configFactory->get('contact.settings') ->set('default_category', $default_category) ->save(); }