3 namespace Drupal\views\Plugin\views\row;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Base class for Views RSS row plugins.
12 abstract class RssPluginBase extends RowPluginBase {
17 * @var \Drupal\Core\Entity\EntityManagerInterface
19 protected $entityManager;
22 * Constructs a RssPluginBase object.
24 * @param array $configuration
25 * A configuration array containing information about the plugin instance.
26 * @param string $plugin_id
27 * The plugin_id for the plugin instance.
28 * @param mixed $plugin_definition
29 * The plugin implementation definition.
30 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
33 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
34 parent::__construct($configuration, $plugin_id, $plugin_definition);
36 $this->entityManager = $entity_manager;
42 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
47 $container->get('entity.manager')
52 * The ID of the entity type for which this is an RSS row plugin.
56 protected $entityTypeId;
61 protected function defineOptions() {
62 $options = parent::defineOptions();
64 $options['view_mode'] = ['default' => 'default'];
72 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
73 parent::buildOptionsForm($form, $form_state);
75 $form['view_mode'] = [
77 '#title' => $this->t('Display type'),
78 '#options' => $this->buildOptionsForm_summary_options(),
79 '#default_value' => $this->options['view_mode'],
84 * Return the main options, which are shown in the summary title.
86 public function buildOptionsForm_summary_options() {
87 $view_modes = $this->entityManager->getViewModes($this->entityTypeId);
89 foreach ($view_modes as $mode => $settings) {
90 $options[$mode] = $settings['label'];
98 public function calculateDependencies() {
99 $dependencies = parent::calculateDependencies();
101 $view_mode = $this->entityManager
102 ->getStorage('entity_view_mode')
103 ->load($this->entityTypeId . '.' . $this->options['view_mode']);
105 $dependencies[$view_mode->getConfigDependencyKey()][] = $view_mode->getConfigDependencyName();
108 return $dependencies;