diff --git a/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php index 0a7d642..8be0e5b 100644 --- a/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php +++ b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php @@ -102,11 +102,8 @@ protected function assertPageCounts($path, $counts, $message) { $this->drupalGet($path); $text = $this->getTextContent(); - // Check the counts. Note that the info and body are both shown on the - // page, and they are the same. So the info/body string should appear on - // the page twice as many times as the input count. foreach ($counts as $langcode => $count) { - $this->assertEqual(substr_count($text, $this->block_content_infos[$langcode]), 2 * $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message); + $this->assertEqual(substr_count($text, $this->block_content_infos[$langcode]), $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message); } } } diff --git a/core/modules/block_content/src/Tests/Views/BlockContentTestBase.php b/core/modules/block_content/src/Tests/Views/BlockContentTestBase.php index 9284b2b..83dc590 100644 --- a/core/modules/block_content/src/Tests/Views/BlockContentTestBase.php +++ b/core/modules/block_content/src/Tests/Views/BlockContentTestBase.php @@ -30,7 +30,7 @@ * @var array */ protected $permissions = array( - 'administer blocks' + 'administer blocks', ); /** diff --git a/core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php b/core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php index f1b1895..a7ecabe 100644 --- a/core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php +++ b/core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php @@ -52,9 +52,9 @@ public function testBlockContentRevisionRelationship() { 'type' => 'basic', 'langcode' => 'en', )); + $block_content->save(); // Create revision of the block_content. $block_content_revision = clone $block_content; -// $block_content_revision->setInfo($this->randomMachineName()); $block_content_revision->setNewRevision(); $block_content_revision->save(); $column_map = array( diff --git a/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_block_content_view.yml b/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_block_content_view.yml index 11f9c9c..8f2d45f 100644 --- a/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_block_content_view.yml +++ b/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_block_content_view.yml @@ -3,7 +3,6 @@ status: true dependencies: module: - block_content - - user id: test_block_content_view label: test_block_content_view module: views @@ -20,9 +19,8 @@ display: position: null display_options: access: - type: perm - options: - perm: 'access content' + type: none + options: { } cache: type: none options: { } diff --git a/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_field_filters.yml b/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_field_filters.yml index e1adec9..899d5ab 100644 --- a/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_field_filters.yml +++ b/core/modules/block_content/tests/modules/block_content_test_views/test_views/views.view.test_field_filters.yml @@ -3,7 +3,6 @@ status: true dependencies: module: - block_content - - user id: test_field_filters label: 'Test field filters' module: views @@ -20,9 +19,8 @@ display: position: 0 display_options: access: - type: perm - options: - perm: 'access content' + type: none + options: { } cache: type: none options: { } diff --git a/core/modules/block_content/src/BlockContentViewsData.php b/core/modules/block_content/src/BlockContentViewsData.php index 2c542bf..d30277f 100644 --- a/core/modules/block_content/src/BlockContentViewsData.php +++ b/core/modules/block_content/src/BlockContentViewsData.php @@ -76,11 +76,19 @@ public function getViewsData() { ), ); + // @todo Fix this when we support block content bulk form. + // $data['block_content']['block_content_bulk_form'] = array( + // 'title' => t('Block Content operations bulk form'), + // 'help' => t('Add a form element that lets you run operations on multiple block contents.'), + // 'field' => array( + // 'id' => 'block_content_bulk_form', + // ), + // ); + // Bogus fields for aliasing purposes. // @todo Add similar support to any date field // @see https://drupal.org/node/2337507 - $data['block_content_field_data']['changed_fulldate'] = array( 'title' => t('Updated date'), 'help' => t('Date in the form of CCYYMMDD.'), @@ -192,7 +200,7 @@ public function getViewsData() { // 'field' => array( // 'title' => t('Link to revert revision'), // 'help' => t('Provide a simple link to revert to the revision.'), - // 'id' => 'block_content_revision_link_revert', //@todo + // 'id' => 'block_content_revision_link_revert', // 'click sortable' => FALSE, // ), // ); @@ -202,7 +210,7 @@ public function getViewsData() { // 'field' => array( // 'title' => t('Link to delete revision'), // 'help' => t('Provide a simple link to delete the content revision.'), - // 'id' => 'block_content_revision_link_delete', //@todo + // 'id' => 'block_content_revision_link_delete', // 'click sortable' => FALSE, // ), // ); diff --git a/core/modules/block_content/src/Plugin/views/field/BlockContent.php b/core/modules/block_content/src/Plugin/views/field/BlockContent.php index 8c1dd0c..e575cfd 100644 --- a/core/modules/block_content/src/Plugin/views/field/BlockContent.php +++ b/core/modules/block_content/src/Plugin/views/field/BlockContent.php @@ -7,11 +7,14 @@ namespace Drupal\block_content\Plugin\views\field; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Field handler to provide simple renderer that allows linking to a block_content. @@ -26,6 +29,54 @@ class BlockContent extends FieldPluginBase { /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * Constructs a new ListingEmpty. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The language manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->languageManager = $language_manager; + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('language_manager'), + $container->get('entity.manager') + ); + } + + /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -75,11 +126,11 @@ protected function renderLink($data, ResultRow $values) { if (!empty($this->options['link_to_block_content']) && !empty($this->additional_fields['id'])) { if ($data !== NULL && $data !== '') { $id = $this->getValue($values, 'id'); - $block_content = entity_load('block_content', $id); + $block_content = $this->entityManager->getStorage('block_content')->load($id); $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = $block_content->url(); if (isset($this->aliases['langcode'])) { - $languages = language_list(); + $languages = $this->languageManager->getLanguages(); $langcode = $this->getValue($values, 'langcode'); if (isset($languages[$langcode])) { $this->options['alter']['language'] = $languages[$langcode]; diff --git a/core/modules/block_content/src/Plugin/views/field/Link.php b/core/modules/block_content/src/Plugin/views/field/Link.php index cdb852e..c5fc646 100644 --- a/core/modules/block_content/src/Plugin/views/field/Link.php +++ b/core/modules/block_content/src/Plugin/views/field/Link.php @@ -81,9 +81,10 @@ public function render(ResultRow $values) { */ protected function renderLink($block_content, ResultRow $values) { // Ensure user has access to view this block_content. -// if (!$block_content->access('view')) { -// return; -// } + if (!$block_content->access('view')) { + return; + } + $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = $block_content->url(); $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('View'); diff --git a/core/modules/block_content/src/Plugin/views/field/LinkDelete.php b/core/modules/block_content/src/Plugin/views/field/LinkDelete.php index 3201304..5d8a79f 100644 --- a/core/modules/block_content/src/Plugin/views/field/LinkDelete.php +++ b/core/modules/block_content/src/Plugin/views/field/LinkDelete.php @@ -23,9 +23,9 @@ class LinkDelete extends Link { */ protected function renderLink($block_content, ResultRow $values) { // Ensure user has access to delete this block_content. -// if (!$block_content->access('delete')) { -// return; -// } + if (!$block_content->access('delete')) { + return; + } $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = $block_content->url('delete-form'); diff --git a/core/modules/block_content/src/Plugin/views/field/LinkEdit.php b/core/modules/block_content/src/Plugin/views/field/LinkEdit.php index 196fed0..1ab8e16 100644 --- a/core/modules/block_content/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/block_content/src/Plugin/views/field/LinkEdit.php @@ -31,9 +31,9 @@ class LinkEdit extends Link { */ protected function renderLink($block_content, ResultRow $values) { // Ensure user has access to edit this block_content. -// if (!$block_content->access('update')) { -// return; -// } + if (!$block_content->access('update')) { + return; + } $this->options['alter']['make_link'] = TRUE; $this->options['alter']['path'] = $block_content->url('edit-form'); diff --git a/core/modules/block_content/src/Plugin/views/field/Path.php b/core/modules/block_content/src/Plugin/views/field/Path.php index c257e18..78116b8 100644 --- a/core/modules/block_content/src/Plugin/views/field/Path.php +++ b/core/modules/block_content/src/Plugin/views/field/Path.php @@ -8,10 +8,12 @@ namespace Drupal\block_content\Plugin\views\field; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\UrlGenerator; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Field handler to present the path to the block_content. @@ -23,6 +25,43 @@ class Path extends FieldPluginBase { /** + * The url generator service. + * + * @var \Drupal\Core\Routing\UrlGenerator + */ + protected $urlGenerator; + + /** + * Constructs a new ListingEmpty. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Routing\UrlGenerator $url_generator + * The url generator service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, UrlGenerator $url_generator) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->urlGenerator = $url_generator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('url_generator') + ); + } + + /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -68,7 +107,7 @@ public function query() { */ public function render(ResultRow $values) { $id = $this->getValue($values, 'id'); - return \Drupal::url('entity.block_content.canonical', ['block_content' => $id], ['absolute' => $this->options['absolute']]); + return $this->urlGenerator->generateFromRoute('entity.block_content.canonical', ['block_content' => $id], ['absolute' => $this->options['absolute']]); } } diff --git a/core/modules/block_content/src/Plugin/views/field/Type.php b/core/modules/block_content/src/Plugin/views/field/Type.php index 1683c41..dd69a7d 100644 --- a/core/modules/block_content/src/Plugin/views/field/Type.php +++ b/core/modules/block_content/src/Plugin/views/field/Type.php @@ -48,7 +48,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { */ function renderName($data, $values) { if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') { - $type = entity_load('block_content_type', $data); + $type = $this->entityManager->getStorage('block_content_type')->load($data); return $type ? $this->t($this->sanitizeValue($type->label())) : ''; } return $this->sanitizeValue($data);