panelizer_quickedit.module in Panelizer 8.3
File
panelizer_quickedit/panelizer_quickedit.module
View source
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Render\Element;
function panelizer_quickedit_render_field(EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
$entity = \Drupal::service('entity.repository')
->getTranslationFromContext($entity, $langcode);
$temp = str_replace('panelizer-', '', $view_mode_id);
list($view_mode, $block_id) = explode('-block-id-', $temp);
$panelizer = \Drupal::service('panelizer');
$display = $panelizer
->getPanelsDisplay($entity, $view_mode);
$plugin = $display
->getBlock($block_id);
$plugin
->setContextValue('entity', $entity);
$build = $plugin
->build();
$build['field']['#view_mode'] = $view_mode_id;
return $build;
}
function panelizer_quickedit_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if (isset($build['#panels_display'])) {
$supported_plugins = [
'ipe',
'standard',
];
if (in_array($build['#panels_display']
->getBuilder()
->getPluginId(), $supported_plugins)) {
$region_names = Element::getVisibleChildren($build['content']);
foreach ($region_names as $region_name) {
$block_ids = Element::getVisibleChildren($build['content'][$region_name]);
foreach ($block_ids as $block_id) {
$block =& $build['content'][$region_name][$block_id];
if (isset($block['#base_plugin_id']) && $block['#base_plugin_id'] === 'entity_field') {
$view_mode = 'panelizer-' . $build['#view_mode'] . '-block-id-' . $block_id;
$block['content']['field']['#view_mode'] = $view_mode;
}
}
}
}
}
}