function ViewsConfigUpdater::processRssViewModeUpdate
Processes views and sets the default RSS view mode if necessary.
Parameters
\Drupal\views\ViewEntityInterface $view: The view entity.
string|null $previous_view_mode: The previous view mode.
Return value
bool TRUE if the view was updated with a default RSS view mode.
2 calls to ViewsConfigUpdater::processRssViewModeUpdate()
- ViewsConfigUpdater::needsRssViewModeUpdate in core/
modules/ views/ src/ ViewsConfigUpdater.php - Checks for views needing a default RSS view mode.
- ViewsConfigUpdater::updateAll in core/
modules/ views/ src/ ViewsConfigUpdater.php - Performs all required updates.
File
-
core/
modules/ views/ src/ ViewsConfigUpdater.php, line 424
Class
- ViewsConfigUpdater
- Provides a BC layer for modules providing old configurations.
Namespace
Drupal\viewsCode
public function processRssViewModeUpdate(ViewEntityInterface $view, ?string $previous_view_mode = NULL) : bool {
$changed = FALSE;
$displays = $view->get('display');
// Row types that need updating.
$row_types = [
'comment_rss' => 'comment',
'node_rss' => 'node',
];
foreach ($displays as &$display) {
if (isset($display['display_options']['row']['options']['view_mode']) && array_key_exists($display['display_options']['row']['type'], $row_types) && $display['display_options']['row']['options']['view_mode'] === 'default') {
// When system.rss is already removed but a view is saved, we still need
// to try and set the view_mode to something more sane. But detecting
// if the view mode was always default, or default because it used the
// system.rss setting is hard. So if there is a default mode available
// it will use that.
// It would make sense to use any RSS view_mode if available, but that
// would mean 'default' can never be set as a view mode. That is an
// issue, therefore, if we have a default view mode available, we will
// use that.
if ($previous_view_mode === NULL) {
$view_modes = $this->entityDisplayRepository
->getViewModes($row_types[$display['display_options']['row']['type']]);
if (array_key_exists('default', $view_modes)) {
return FALSE;
}
// If there is no default, the most likely view mode is RSS. If that
// is available we use that. Otherwise, fall back to the first
// available.
$probable_view_mode = isset($view_modes['rss']) ? 'rss' : array_key_first($view_modes);
$display['display_options']['row']['options']['view_mode'] = $probable_view_mode;
$changed = TRUE;
}
else {
$display['display_options']['row']['options']['view_mode'] = $previous_view_mode;
$changed = TRUE;
}
}
}
if ($changed) {
$view->set('display', $displays);
}
return $changed;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.