Skip to content
Snippets Groups Projects

Issue #2816447 by kriboogh: Get feed title in correct language

Issue #2816447 by kriboogh: Get feed title in correct language

Closes #2816447

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
39 58 * The entity type manager.
40 59 * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
41 60 * The entity display repository.
61 * @param \Drupal\Core\Language\LanguageManagerInterface|null $language_manager
62 * The language manager.
63 * @param \Drupal\Core\Entity\EntityRepositoryInterface|null $entity_repository
64 * The entity repository.
42 65 */
43 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
66 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ?LanguageManagerInterface $language_manager = NULL, ?EntityRepositoryInterface $entity_repository = NULL) {
44 67 parent::__construct($configuration, $plugin_id, $plugin_definition);
45 68
46 69 $this->entityTypeManager = $entity_type_manager;
47 70 $this->entityDisplayRepository = $entity_display_repository;
71 if ($language_manager === NULL) {
72 @trigger_error('The language_manager service must be passed to RssPluginBase::__construct(), it is required before Drupal 10.0.0.', E_USER_WARNING);
  • 63 * @param \Drupal\Core\Entity\EntityRepositoryInterface|null $entity_repository
    64 * The entity repository.
    42 65 */
    43 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
    66 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ?LanguageManagerInterface $language_manager = NULL, ?EntityRepositoryInterface $entity_repository = NULL) {
    44 67 parent::__construct($configuration, $plugin_id, $plugin_definition);
    45 68
    46 69 $this->entityTypeManager = $entity_type_manager;
    47 70 $this->entityDisplayRepository = $entity_display_repository;
    71 if ($language_manager === NULL) {
    72 @trigger_error('The language_manager service must be passed to RssPluginBase::__construct(), it is required before Drupal 10.0.0.', E_USER_WARNING);
    73 $language_manager = \Drupal::service('language_manager');
    74 }
    75 $this->languageManager = $language_manager;
    76 if ($entity_repository === NULL) {
    77 @trigger_error('The entity.repository service must be passed to RssPluginBase::__construct(), it is required before Drupal 10.0.0.', E_USER_WARNING);
  • 26 31 */
    27 32 protected $entityDisplayRepository;
    28 33
    34 /**
    35 * The language manager.
    36 *
    37 * @var \Drupal\Core\Language\LanguageManagerInterface
    38 */
    39 protected $languageManager;
  • 26 31 */
    27 32 protected $entityDisplayRepository;
    28 33
    34 /**
    35 * The language manager.
    36 *
    37 * @var \Drupal\Core\Language\LanguageManagerInterface
    38 */
    39 protected $languageManager;
    40
    41 /**
    42 * The entity repository.
    43 *
    44 * @var \Drupal\Core\Entity\EntityRepositoryInterface
    45 */
    46 protected $entityRepository;
  • 133 133 $this->checkFeedResults('path-alias', $node);
    134 134 }
    135 135
    136 /**
    137 * Tests that rendered node content is in current language.
    138 */
    139 public function testFeedTranslation() {
  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 40 69 * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
    41 70 * The entity display repository.
    71 * @param \Drupal\Core\Language\LanguageManagerInterface|null $language_manager
    72 * The language manager.
    73 * @param \Drupal\Core\Entity\EntityRepositoryInterface|null $entity_repository
    74 * The entity repository.
    42 75 */
    43 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
    76 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ?LanguageManagerInterface $language_manager = NULL, ?EntityRepositoryInterface $entity_repository = NULL) {
    44 77 parent::__construct($configuration, $plugin_id, $plugin_definition);
    45 78
    46 79 $this->entityTypeManager = $entity_type_manager;
    47 80 $this->entityDisplayRepository = $entity_display_repository;
    81
    82 if ($language_manager === NULL) {
    83 @trigger_error('Passing null as the language_manager service to RssPluginBase::__construct() is deprecated in drupal:10.4.0 and is required from drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/2816447', E_USER_DEPRECATED);
    • The usual way this is expressed is

      Suggested change
      83 @trigger_error('Passing null as the language_manager service to RssPluginBase::__construct() is deprecated in drupal:10.4.0 and is required from drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/2816447', E_USER_DEPRECATED);
      83 @trigger_error('Calling ' . __METHOD__ . ' without the $langugage_manager argument is deprecated in drupal:11.1.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/TBA', E_USER_DEPRECATED);
    • Please register or sign in to reply
  • 43 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
    76 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ?LanguageManagerInterface $language_manager = NULL, ?EntityRepositoryInterface $entity_repository = NULL) {
    44 77 parent::__construct($configuration, $plugin_id, $plugin_definition);
    45 78
    46 79 $this->entityTypeManager = $entity_type_manager;
    47 80 $this->entityDisplayRepository = $entity_display_repository;
    81
    82 if ($language_manager === NULL) {
    83 @trigger_error('Passing null as the language_manager service to RssPluginBase::__construct() is deprecated in drupal:10.4.0 and is required from drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/2816447', E_USER_DEPRECATED);
    84 $language_manager = \Drupal::service('language_manager');
    85 }
    86
    87 $this->languageManager = $language_manager;
    88
    89 if ($entity_repository === NULL) {
    90 @trigger_error('Passing null as the entity.repository service to RssPluginBase::__construct() is deprecated in drupal:10.4.0 and is required from drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/2816447', E_USER_DEPRECATED);
    • Suggested change
      90 @trigger_error('Passing null as the entity.repository service to RssPluginBase::__construct() is deprecated in drupal:10.4.0 and is required from drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/2816447', E_USER_DEPRECATED);
      90 @trigger_error('Calling ' . __METHOD__ . ' without the $entity_repository argment is deprecated in drupal:11.1.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/TBA', E_USER_DEPRECATED)
    • Please register or sign in to reply
  • 94 136
    95 137 /**
    96 138 * Return the main options, which are shown in the summary title.
    139 *
    140 * @return array
    141 * The main options for the summary.
    97 142 */
    98 143 public function buildOptionsForm_summary_options() {
    99 144 $view_modes = $this->entityDisplayRepository->getViewModes($this->entityTypeId);
    100 145 $options = [];
    146
  • 94 136
    95 137 /**
    96 138 * Return the main options, which are shown in the summary title.
    139 *
    140 * @return array
    141 * The main options for the summary.
    97 142 */
    98 143 public function buildOptionsForm_summary_options() {
    99 144 $view_modes = $this->entityDisplayRepository->getViewModes($this->entityTypeId);
    100 145 $options = [];
    146
    101 147 foreach ($view_modes as $mode => $settings) {
    102 148 $options[$mode] = $settings['label'];
    103 149 }
    150
  • 94 136
    95 137 /**
    96 138 * Return the main options, which are shown in the summary title.
    139 *
    140 * @return array
    141 * The main options for the summary.
  • 103 149 }
    150
    104 151 return $options;
    105 152 }
    106 153
    107 154 /**
    108 155 * {@inheritdoc}
    109 156 */
    110 public function calculateDependencies() {
    157 public function calculateDependencies(): array {
    111 158 $dependencies = parent::calculateDependencies();
    112 159
    113 $view_mode = $this->entityTypeManager
    114 ->getStorage('entity_view_mode')
    115 ->load($this->entityTypeId . '.' . $this->options['view_mode']);
    160 try {
  • 108 155 * {@inheritdoc}
    109 156 */
    110 public function calculateDependencies() {
    157 public function calculateDependencies(): array {
    111 158 $dependencies = parent::calculateDependencies();
    112 159
    113 $view_mode = $this->entityTypeManager
    114 ->getStorage('entity_view_mode')
    115 ->load($this->entityTypeId . '.' . $this->options['view_mode']);
    160 try {
    161 $view_mode = $this->entityTypeManager
    162 ->getStorage('entity_view_mode')
    163 ->load($this->entityTypeId . '.' . $this->options['view_mode']);
    164 }
    165 catch (InvalidPluginDefinitionException | PluginNotFoundException $e) {
    166 \Drupal::logger('views')->error('Could not load entity view mode %view_mode', [
  • 142 173 * @param \Drupal\node\Entity\Node $node
    143 174 * The node entity that's been created.
    144 175 */
    145 protected function checkFeedResults($link_style, Node $node) {
    176 protected function checkFeedResults($link_style, Node $node): void {
  • 148 $es_translation->set('body', [['value' => 'Algo en Español']]);
    149 $es_translation->save();
    150
    151 // Visit the page in english and assert title in English language.
    152 $this->drupalGet('rss.xml');
    153 $items = $this->getSession()->getDriver()->find('//channel/item');
    154 foreach ($items as $item) {
    155 $title_element = $item->findAll('xpath', 'title');
    156 $this->assertEquals('Something in English', $title_element[0]->getText());
    157 }
    158
    159 // Visit the page in spanish and assert title in Spanish language.
    160 $this->drupalGet('es/rss.xml');
    161 foreach ($items as $item) {
    162 $title_element = $item->findAll('xpath', 'title');
    163 $this->assertEquals('Algo en Español', $title_element[0]->getText());
  • Nic Rodgers added 508 commits

    added 508 commits

    Compare with previous version

  • Please register or sign in to reply
    Loading