public View::duplicateDisplayAsType($old_display_id, $new_display_type)
Duplicates an existing display into a new display type.
For example clone to display a page display as a block display.
Parameters
string $old_display_id: The origin of the duplicated display.
string $new_display_type: The display type of the new display.
Return value
string The display ID of the new display.
Overrides ViewEntityInterface::duplicateDisplayAsType
File
- core/modules/views/src/Entity/View.php, line 237
Class
- View
- Defines a View configuration entity class.
Namespace
Drupal\views\Entity
Code
public function duplicateDisplayAsType($old_display_id, $new_display_type) { $executable = $this->getExecutable(); $display = $executable->newDisplay($new_display_type); $new_display_id = $display->display['id']; $displays = $this->get('display'); // Let the display title be generated by the addDisplay method and set the // right display plugin, but keep the rest from the original display. $display_duplicate = $displays[$old_display_id]; unset($display_duplicate['display_title']); unset($display_duplicate['display_plugin']); $displays[$new_display_id] = NestedArray::mergeDeep($displays[$new_display_id], $display_duplicate); $displays[$new_display_id]['id'] = $new_display_id; // First set the displays. $this->set('display', $displays); // Ensure that we just copy display options, which are provided by the new // display plugin. $executable->setDisplay($new_display_id); $executable->display_handler->filterByDefinedOptions($displays[$new_display_id]['display_options']); // Update the display settings. $this->set('display', $displays); return $new_display_id; }
Please login to continue.