.../aggregator/src/Plugin/views/row/Rss.php | 30 +-------- core/modules/comment/src/Plugin/views/row/Rss.php | 57 +++------------- core/modules/node/src/Plugin/views/row/Rss.php | 37 +++-------- .../views/src/Plugin/views/row/EntityRow.php | 4 +- .../views/src/Plugin/views/row/RssPluginBase.php | 77 ++++++++++++++++++++++ 5 files changed, 100 insertions(+), 105 deletions(-) diff --git a/core/modules/aggregator/src/Plugin/views/row/Rss.php b/core/modules/aggregator/src/Plugin/views/row/Rss.php index 2b6dba1..72410e5 100644 --- a/core/modules/aggregator/src/Plugin/views/row/Rss.php +++ b/core/modules/aggregator/src/Plugin/views/row/Rss.php @@ -7,8 +7,7 @@ namespace Drupal\aggregator\Plugin\views\row; -use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\views\row\RowPluginBase; +use Drupal\views\Plugin\views\row\RssPluginBase; /** * Defines a row plugin which loads an aggregator item and renders as RSS. @@ -22,7 +21,7 @@ * display_types = {"feed"} * ) */ -class Rss extends RowPluginBase { +class Rss extends RssPluginBase { /** * The table the aggregator item is using for storage. @@ -41,30 +40,7 @@ class Rss extends RowPluginBase { /** * {@inheritdoc} */ - protected function defineOptions() { - $options = parent::defineOptions(); - - $options['view_mode'] = array('default' => 'default'); - - return $options; - } - - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - $form['view_mode'] = array( - '#type' => 'select', - '#title' => $this->t('Display type'), - '#options' => array( - 'fulltext' => $this->t('Full text'), - 'teaser' => $this->t('Title plus teaser'), - 'title' => $this->t('Title only'), - 'default' => $this->t('Use default RSS settings'), - ), - '#default_value' => $this->options['view_mode'], - ); - } + protected $entityTypeId = 'aggregator_item'; /** * {@inheritdoc} diff --git a/core/modules/comment/src/Plugin/views/row/Rss.php b/core/modules/comment/src/Plugin/views/row/Rss.php index 8193546..bbbce01 100644 --- a/core/modules/comment/src/Plugin/views/row/Rss.php +++ b/core/modules/comment/src/Plugin/views/row/Rss.php @@ -7,8 +7,7 @@ namespace Drupal\comment\Plugin\views\row; -use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\views\row\RowPluginBase; +use Drupal\views\Plugin\views\row\RssPluginBase; /** * Plugin which formats the comments as RSS items. @@ -23,29 +22,15 @@ * display_types = {"feed"} * ) */ -class Rss extends RowPluginBase { +class Rss extends RssPluginBase { var $base_table = 'comment'; var $base_field = 'cid'; - protected function defineOptions() { - $options = parent::defineOptions(); - - $options['view_mode'] = array('default' => 'default'); - - return $options; - } - - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - parent::buildOptionsForm($form, $form_state); - - $form['view_mode'] = array( - '#type' => 'select', - '#title' => $this->t('Display type'), - '#options' => $this->options_form_summary_options(), - '#default_value' => $this->options['view_mode'], - ); - } + /** + * {@inheritdoc} + */ + protected $entityTypeId = 'comment'; public function preRender($result) { $cids = array(); @@ -62,18 +47,10 @@ public function preRender($result) { } /** - * Return the main options, which are shown in the summary title - * - * @see views_plugin_row_node_rss::options_form_summary_options() - * @todo: Maybe provide a views_plugin_row_rss_entity and reuse this method - * in views_plugin_row_comment|node_rss.inc + * {@inheritdoc} */ - function options_form_summary_options() { - $view_modes = \Drupal::entityManager()->getViewModes('node'); - $options = array(); - foreach ($view_modes as $mode => $settings) { - $options[$mode] = $settings['label']; - } + public function buildOptionsForm_summary_options() { + $options = parent::buildOptionsForm_summary_options(); $options['title'] = $this->t('Title only'); $options['default'] = $this->t('Use site default RSS settings'); return $options; @@ -149,20 +126,4 @@ public function render($row) { return drupal_render_root($build); } - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - $dependencies = parent::calculateDependencies(); - - $view_mode = \Drupal::entityManager() - ->getStorage('entity_view') - ->load($this->options['view_mode']); - if ($view_mode) { - $dependencies['config'][] = $view_mode->getConfigDependencyName(); - } - - return $dependencies; - } - } diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php index 4ee566e..f2f5a50 100644 --- a/core/modules/node/src/Plugin/views/row/Rss.php +++ b/core/modules/node/src/Plugin/views/row/Rss.php @@ -9,8 +9,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\String; -use Drupal\Core\Form\FormStateInterface; -use Drupal\views\Plugin\views\row\RowPluginBase; +use Drupal\views\Plugin\views\row\RssPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\node\NodeStorageInterface; @@ -28,7 +27,7 @@ * display_types = {"feed"} * ) */ -class Rss extends RowPluginBase { +class Rss extends RssPluginBase { // Basic properties that let the row style follow relationships. var $base_table = 'node'; @@ -39,6 +38,11 @@ class Rss extends RowPluginBase { var $nodes = array(); /** + * {@inheritdoc} + */ + protected $entityTypeId = 'node'; + + /** * The node storage * * @var \Drupal\node\NodeStorageInterface @@ -74,34 +78,11 @@ public static function create(ContainerInterface $container, array $configuratio ); } - protected function defineOptions() { - $options = parent::defineOptions(); - - $options['view_mode'] = array('default' => 'default'); - - return $options; - } - - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - parent::buildOptionsForm($form, $form_state); - - $form['view_mode'] = array( - '#type' => 'select', - '#title' => $this->t('Display type'), - '#options' => $this->buildOptionsForm_summary_options(), - '#default_value' => $this->options['view_mode'], - ); - } - /** - * Return the main options, which are shown in the summary title. + * {@inheritdoc} */ public function buildOptionsForm_summary_options() { - $view_modes = \Drupal::entityManager()->getViewModes('node'); - $options = array(); - foreach ($view_modes as $mode => $settings) { - $options[$mode] = $settings['label']; - } + $options = parent::buildOptionsForm_summary_options(); $options['title'] = $this->t('Title only'); $options['default'] = $this->t('Use site default RSS settings'); return $options; diff --git a/core/modules/views/src/Plugin/views/row/EntityRow.php b/core/modules/views/src/Plugin/views/row/EntityRow.php index af27439..af12083 100644 --- a/core/modules/views/src/Plugin/views/row/EntityRow.php +++ b/core/modules/views/src/Plugin/views/row/EntityRow.php @@ -220,8 +220,8 @@ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); $view_mode = \Drupal::entityManager() - ->getStorage('entity_view') - ->load($this->options['view_mode']); + ->getStorage('entity_view_display') + ->load($this->entityTypeId . '.' . $this->options['view_mode']); if ($view_mode) { $dependencies['config'][] = $view_mode->getConfigDependencyName(); } diff --git a/core/modules/views/src/Plugin/views/row/RssPluginBase.php b/core/modules/views/src/Plugin/views/row/RssPluginBase.php new file mode 100644 index 0000000..5ca3f6b --- /dev/null +++ b/core/modules/views/src/Plugin/views/row/RssPluginBase.php @@ -0,0 +1,77 @@ + 'default'); + + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + parent::buildOptionsForm($form, $form_state); + + $form['view_mode'] = array( + '#type' => 'select', + '#title' => $this->t('Display type'), + '#options' => $this->buildOptionsForm_summary_options(), + '#default_value' => $this->options['view_mode'], + ); + } + + /** + * Return the main options, which are shown in the summary title. + */ + public function buildOptionsForm_summary_options() { + $view_modes = \Drupal::entityManager()->getViewModes('node'); + $options = array(); + foreach ($view_modes as $mode => $settings) { + $options[$mode] = $settings['label']; + } + return $options; + } + + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + $dependencies = parent::calculateDependencies(); + + $view_mode = \Drupal::entityManager() + ->getStorage('entity_view_mode') + ->load($this->entityTypeId . '.' . $this->options['view_mode']); + if ($view_mode) { + $dependencies['config'][] = $view_mode->getConfigDependencyName(); + } + + return $dependencies; + } + +}