You are here

public static function ConfigPages::config in Config Pages 8.2

Same name and namespace in other branches
  1. 8.3 src/Entity/ConfigPages.php \Drupal\config_pages\Entity\ConfigPages::config()
  2. 8 src/Entity/ConfigPages.php \Drupal\config_pages\Entity\ConfigPages::config()
5 calls to ConfigPages::config()
ConfigPagesBlock::build in src/Plugin/Block/ConfigPagesBlock.php
Builds and returns the renderable array for this block plugin.
ConfigPagesBlock::getCacheTags in src/Plugin/Block/ConfigPagesBlock.php
The cache tags associated with this object.
ConfigPagesLoaderService::load in src/ConfigPagesLoaderService.php
Loads config page entity by type and context.
ConfigPagesStorage::load in src/ConfigPagesStorage.php
Loads one entity.
config_pages_config in ./config_pages.module
Helper function.

File

src/Entity/ConfigPages.php, line 171

Class

ConfigPages
Defines the config page entity class.

Namespace

Drupal\config_pages\Entity

Code

public static function config($type, $context = NULL) {

  // Build conditions.
  if (!empty($type)) {
    $conditions['type'] = $type;

    // Get current context if NULL.
    if ($context == NULL) {
      $type = ConfigPagesType::load($type);
      if (!is_object($type)) {
        return NULL;
      }
      $conditions['context'] = $type
        ->getContextData();
    }
    else {
      $conditions['context'] = $context;
    }
    $list = \Drupal::entityTypeManager()
      ->getStorage('config_pages')
      ->loadByProperties($conditions);
  }

  // Try to get the fallback config page.
  if (!$list && $context == NULL) {
    $conditions['context'] = $type
      ->getContextData(TRUE);
    $list = \Drupal::entityTypeManager()
      ->getStorage('config_pages')
      ->loadByProperties($conditions);
  }
  return $list ? current($list) : NULL;
}