1 layout.entity.admin.inc layout_get_entity_layouts($entity_type, $bundle_name = '')

Returns layouts with visibility conditions matching an entity type or bundle.

Parameters

string $entity_type: The entity type.

string $bundle_name: The entity bundle name.

Return value

array: Associative array of matched layouts. Array keys:

  • all: An array of all layouts that apply to this entity type, as well as
  • layouts with visibility conditions matching $bundle_name if provided. layouts without bundle visibility conditions.

    • bundles: An array of layouts with visibility conditions for this bundle type if the $bundle_name parameter is provided.

File

core/modules/layout/layout.entity.admin.inc, line 123
Provides a user interface for managing layouts for entity bundles.

Code

function layout_get_entity_layouts($entity_type, $bundle_name = '') {
  $all_layouts = layout_load_all();
  $matched_layouts = array('all' => array(), 'bundles' => array());
  foreach ($all_layouts as $layout) {
    if ($path = $layout->getPath()) {
      $path_contexts = layout_context_required_by_path($path);
      foreach ($path_contexts as $path_context) {
        if (is_a($path_context, 'EntityLayoutContext') && $path_context->isA($entity_type)) {
          if (empty($layout->conditions)) {
            $matched_layouts['all'][] = $layout;
          }
          else {
            foreach ($layout->conditions as $condition) {
              if (is_a($condition, 'EntityBundleLayoutAccess')) {
                if (empty($bundle_name)) {
                  $matched_layouts['all'][] = $layout;
                  foreach ($condition->settings['bundles'] as $bundle) {
                    $matched_layouts['bundles'][$bundle][] = $layout;
                  }
                }
                elseif (in_array($bundle_name, $condition->settings['bundles'])) {
                  $matched_layouts['all'][] = $layout;
                  $matched_layouts['bundles'][$bundle_name][] = $layout;
                  break;
                }
              }
            }
          }
        }
      }
    }
  }

  return $matched_layouts;

}