function ctools_entity_mask_copy_display

Same name in other branches
  1. 8.x-3.x modules/ctools_entity_mask/ctools_entity_mask.module \ctools_entity_mask_copy_display()

Copies all components from a display for a masked entity type.

If the given display is for a mask entity type, the corresponding display for the masked entity type is loaded and all of its components are copied into the given display. If no corresponding display exists for the masked entity type, the default display will be loaded and used.

Parameters

\Drupal\Core\Entity\Display\EntityDisplayInterface $display: The display for the mask entity type.

4 calls to ctools_entity_mask_copy_display()
ctools_entity_mask_entity_form_display_alter in modules/ctools_entity_mask/ctools_entity_mask.module
Implements hook_entity_form_display_alter().
ctools_entity_mask_entity_form_display_create in modules/ctools_entity_mask/ctools_entity_mask.module
Implements hook_ENTITY_TYPE_create().
ctools_entity_mask_entity_view_display_alter in modules/ctools_entity_mask/ctools_entity_mask.module
Implements hook_entity_view_display_alter().
ctools_entity_mask_entity_view_display_create in modules/ctools_entity_mask/ctools_entity_mask.module
Implements hook_ENTITY_TYPE_create().

File

modules/ctools_entity_mask/ctools_entity_mask.module, line 81

Code

function ctools_entity_mask_copy_display(EntityDisplayInterface $display) {
    $mask = \Drupal::entityTypeManager()->getDefinition($display->getTargetEntityTypeId())
        ->get('mask');
    // If the target entity type is not masking another entity type, there is
    // nothing to do here.
    if (empty($mask)) {
        return;
    }
    // Try to load the corresponding entity display for the masked entity type,
    // in descending order of preference.
    $bundle = $display->getTargetBundle();
    $displays = $display::loadMultiple([
        $mask . '.' . $bundle . '.' . $display->getMode(),
        $mask . '.' . $bundle . '.default',
    ]);
    // Nothing to do if there is no display we can borrow components from.
    if (empty($displays)) {
        return;
    }
    foreach (reset($displays)->getComponents() as $key => $component) {
        $display->setComponent($key, $component);
    }
}