diff --git a/core/modules/aggregator/aggregator.services.yml b/core/modules/aggregator/aggregator.services.yml index 2296922..c2828c9 100644 --- a/core/modules/aggregator/aggregator.services.yml +++ b/core/modules/aggregator/aggregator.services.yml @@ -15,4 +15,4 @@ services: - { name: access_check } aggregator.category.storage: class: Drupal\aggregator\CategoryStorageController - arguments: ['@database', '@plugin.manager.entity', '@module_handler'] + arguments: ['@database'] diff --git a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php index 77e978d..299113c 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php @@ -22,6 +22,13 @@ class CategoryStorageController implements CategoryStorageControllerInterface { protected $database; /** + * A cache of loaded categories. + * + * @var \stdClass[] + */ + protected $categories; + + /** * Creates a new CategoryStorageController object. * * @param \Drupal\Core\Database\Connection $database @@ -35,17 +42,20 @@ public function __construct(Connection $database) { * {@inheritdoc} */ public function load($cid) { - return $this->database->query("SELECT * FROM {aggregator_category} WHERE cid = :cid", array(':cid' => $cid))->fetchObject(); + if (!isset($this->categories[$cid])) { + $this->categories[$cid] = $this->database->query("SELECT * FROM {aggregator_category} WHERE cid = :cid", array(':cid' => $cid))->fetchObject(); + } + return $this->categories[$cid]; } /** * {@inheritdoc} */ - public function save(array $category) { + public function save($category) { $cid = $this->database->insert('aggregator_category') ->fields(array( - 'title' => $category['title'], - 'description' => $category['description'], + 'title' => $category->title, + 'description' => $category->description, 'block' => 5, )) ->execute(); @@ -55,12 +65,12 @@ public function save(array $category) { /** * {@inheritdoc} */ - public function update(array $category) { + public function update($category) { $this->database->merge('aggregator_category') - ->key(array('cid' => $category['cid'])) + ->key(array('cid' => $category->cid)) ->fields(array( - 'title' => $category['title'], - 'description' => $category['description'], + 'title' => $category->title, + 'description' => $category->description, )) ->execute(); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php index c3e9e0a..a4ab4db 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php @@ -19,28 +19,28 @@ * The unique category ID. * * @return stdClass|null - * An array of category properties. + * An object containing all category properties. */ public function load($cid); /** * Saves an aggregator category. * - * @param array $category + * @param \stdClass $category * The category to save. * * @return int * The new category ID. */ - public function save(array $category); + public function save($category); /** * Updates and aggregator category. * - * @param array $category + * @param \stdClass $category * The category. */ - public function update(array $category); + public function update($category); /** * Deletes an aggregator category. diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php index 219e17f..987dc1e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php @@ -174,7 +174,7 @@ public function submitForm(array &$form, array &$form_state) { // Update the category. if (!empty($form_state['values']['cid'])) { $cid = $form_state['values']['cid']; - $this->categoryStorageController->update($form_state['values']); + $this->categoryStorageController->update((object) $form_state['values']); drupal_set_message(t('The category %category has been updated.', array('%category' => $title))); if (preg_match('/^\/admin/', $this->request->getPathInfo())) { $form_state['redirect'] = 'admin/config/services/aggregator/'; @@ -187,7 +187,7 @@ public function submitForm(array &$form, array &$form_state) { } // Insert the category. - $cid = $this->categoryStorageController->save($form_state['values']); + $cid = $this->categoryStorageController->save((object) $form_state['values']); watchdog('aggregator', 'Category %category added.', array('%category' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/config/services/aggregator')); drupal_set_message(t('The category %category has been added.', array('%category' => $title))); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php index c057bd1..038e3cc 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php @@ -51,7 +51,9 @@ class CategoryDeleteForm extends ConfirmFormBase implements ControllerInterface protected $categoryStorageController; /** - * @var + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request */ protected $request;