RssPluginBase.php in Zircon Profile 8
File
core/modules/views/src/Plugin/views/row/RssPluginBase.php
View source
<?php
namespace Drupal\views\Plugin\views\row;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class RssPluginBase extends RowPluginBase {
protected $entityManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityManager = $entity_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity.manager'));
}
protected $entityTypeId;
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'],
);
}
public function buildOptionsForm_summary_options() {
$view_modes = $this->entityManager
->getViewModes($this->entityTypeId);
$options = array();
foreach ($view_modes as $mode => $settings) {
$options[$mode] = $settings['label'];
}
return $options;
}
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$view_mode = $this->entityManager
->getStorage('entity_view_mode')
->load($this->entityTypeId . '.' . $this->options['view_mode']);
if ($view_mode) {
$dependencies[$view_mode
->getConfigDependencyKey()][] = $view_mode
->getConfigDependencyName();
}
return $dependencies;
}
}