diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php index c9fe040..a7d47e8 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php @@ -17,8 +17,7 @@ * @Plugin( * id = "aggregator_category_block", * admin_label = @Translation("Aggregator category"), - * module = "aggregator", - * derivative = "Drupal\aggregator\Plugin\Derivative\AggregatorCategoryBlock" + * module = "aggregator" * ) */ class AggregatorCategoryBlock extends BlockBase { @@ -29,6 +28,7 @@ class AggregatorCategoryBlock extends BlockBase { public function settings() { // By default, the block will contain 10 feed items. return array( + 'cid' => 0, 'block_count' => 10, ); } @@ -45,6 +45,18 @@ public function access() { * Overrides \Drupal\block\BlockBase::blockForm(). */ public function blockForm($form, &$form_state) { + $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); + $options = array(); + foreach ($result as $category) { + $options[$category->cid] = check_plain($category->title); + } + + $form['cid'] = array( + '#type' => 'select', + '#title' => t('Select the category that should be displayed'), + '#default_value' => $this->configuration['cid'], + '#options' => $options, + ); $form['block_count'] = array( '#type' => 'select', '#title' => t('Number of news items in block'), @@ -58,6 +70,7 @@ public function blockForm($form, &$form_state) { * Overrides \Drupal\block\BlockBase::blockSubmit(). */ public function blockSubmit($form, &$form_state) { + $this->configuration['cid'] = $form_state['values']['cid']; $this->configuration['block_count'] = $form_state['values']['block_count']; } @@ -65,8 +78,8 @@ public function blockSubmit($form, &$form_state) { * {@inheritdoc} */ public function build() { - $id = $this->getPluginId(); - if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) { + $cid = $this->configuration['cid']; + if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchObject()) { $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid)); $more_link = array( '#theme' => 'more_link', diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorCategoryBlock.php deleted file mode 100644 index 8f096fb..0000000 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Derivative/AggregatorCategoryBlock.php +++ /dev/null @@ -1,103 +0,0 @@ -basePluginId = $base_plugin_id; - $this->connection = $connection; - $this->translationManager = $translation_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $base_plugin_id) { - return new static( - $base_plugin_id, - $container->get('database'), - $container->get('string_translation') - ); - } - - /** - * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinition(). - */ - public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) { - if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) { - return $this->derivatives[$derivative_id]; - } - $result = $this->connection->query('SELECT cid, title FROM {aggregator_category} ORDER BY title WHERE cid = :cid', array(':cid' => $derivative_id))->fetchObject(); - $this->derivatives[$derivative_id] = $base_plugin_definition; - $this->derivatives[$derivative_id]['admin_label'] = $this->translationManager->translate('@title category latest items', array('@title' => $result->title)); - return $this->derivatives[$derivative_id]; - } - - /** - * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions(). - */ - public function getDerivativeDefinitions(array $base_plugin_definition) { - // Provide a block plugin definition for each aggregator category. - $result = $this->connection->query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); - foreach ($result as $category) { - $this->derivatives[$category->cid] = $base_plugin_definition; - $this->derivatives[$category->cid]['admin_label'] = $this->translationManager->translate('@title category latest items', array('@title' => $category->title)); - } - return $this->derivatives; - } - -} diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php index 126aff0..084b85d 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php @@ -7,20 +7,21 @@ namespace Drupal\block\Tests; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\Language; -use Drupal\aggregator\Tests\AggregatorTestBase; +use Drupal\simpletest\WebTestBase; /** * Tests multilingual block definition caching. */ -class BlockLanguageCacheTest extends AggregatorTestBase { +class BlockLanguageCacheTest extends WebTestBase { /** * Modules to enable. * * @var array */ - public static $modules = array('block', 'language'); + public static $modules = array('block', 'language', 'menu'); /** * List of langcodes. @@ -32,7 +33,7 @@ class BlockLanguageCacheTest extends AggregatorTestBase { public static function getInfo() { return array( 'name' => 'Multilingual blocks', - 'description' => 'Checks display of aggregator blocks with multiple languages.', + 'description' => 'Checks display of menu blocks with multiple languages.', 'group' => 'Block', ); } @@ -60,10 +61,7 @@ public function testBlockLinks() { $admin_user = $this->drupalCreateUser(array( 'administer blocks', 'access administration pages', - 'administer news feeds', - 'access news feeds', - 'create article content', - 'administer languages', + 'administer menu', )); $this->drupalLogin($admin_user); @@ -73,15 +71,17 @@ public function testBlockLinks() { $this->clickLink(t('Place blocks')); } - // Create a feed in the default language. - $this->createSampleNodes(); - $feed = $this->createFeed(); + // Create a menu in the default language. + $edit['label'] = $this->randomName(); + $edit['id'] = Unicode::strtolower($edit['label']); + $this->drupalPost('admin/structure/menu/add', $edit, t('Save')); + $this->assertText(t('Menu @label has been added.', array('@label' => $edit['label']))); // Check that the block is listed for all languages. foreach ($this->langcodes as $langcode) { $this->drupalGet('admin/structure/block', array('language' => $langcode)); $this->clickLink(t('Place blocks')); - $this->assertText($feed->label()); + $this->assertText($edit['label']); } } }