コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function uninstall($type, $name)
 {
     // Remove all dependent configuration entities.
     $dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
     // Reverse the array to that entities are removed in the correct order of
     // dependence. For example, this ensures that field instances are removed
     // before fields.
     foreach (array_reverse($dependent_entities) as $entity) {
         $entity->setUninstalling(TRUE);
         $entity->delete();
     }
     $config_names = $this->configFactory->listAll($name . '.');
     foreach ($config_names as $config_name) {
         $this->configFactory->get($config_name)->delete();
     }
     // Remove any matching configuration from collections.
     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->activeStorage->createCollection($collection);
         $collection_storage->deleteAll($name . '.');
     }
     $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
     if (is_dir($schema_dir)) {
         // Refresh the schema cache if uninstalling an extension that provides
         // configuration schema.
         $this->typedConfigManager->clearCachedDefinitions();
     }
 }
コード例 #2
0
 /**
  * Retrieves the list of available view modes for the current node.
  *
  * @param EntityInterface $node
  *   The node being previewed.
  *
  * @return array
  *   List of available view modes for the current node.
  */
 protected function getViewModeOptions(EntityInterface $node)
 {
     $load_ids = array();
     $view_mode_options = array();
     // Load all the node's view modes.
     $view_modes = $this->entityManager->getViewModes('node');
     // Get the list of available view modes for the current node's bundle.
     $ids = $this->configFactory->listAll('core.entity_view_display.node.' . $node->bundle());
     foreach ($ids as $id) {
         $config_id = str_replace('core.entity_view_display' . '.', '', $id);
         $load_ids[] = $config_id;
     }
     $displays = entity_load_multiple('entity_view_display', $load_ids);
     // Generate the display options array.
     foreach ($displays as $display) {
         $view_mode_name = $display->get('mode');
         // Skip view modes that are not used in the front end.
         if (in_array($view_mode_name, array('rss', 'search_index'))) {
             continue;
         }
         if ($display->status()) {
             $view_mode_options[$view_mode_name] = $view_mode_name == 'default' ? t('Default') : $view_modes[$view_mode_name]['label'];
         }
     }
     return $view_mode_options;
 }
コード例 #3
0
ファイル: ConfigManager.php プロジェクト: frankcr/sftw8
 /**
  * {@inheritdoc}
  */
 public function uninstall($type, $name)
 {
     $entities = $this->getConfigEntitiesToChangeOnDependencyRemoval($type, [$name], FALSE);
     // Fix all dependent configuration entities.
     /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
     foreach ($entities['update'] as $entity) {
         $entity->save();
     }
     // Remove all dependent configuration entities.
     foreach ($entities['delete'] as $entity) {
         $entity->setUninstalling(TRUE);
         $entity->delete();
     }
     $config_names = $this->configFactory->listAll($name . '.');
     foreach ($config_names as $config_name) {
         $this->configFactory->getEditable($config_name)->delete();
     }
     // Remove any matching configuration from collections.
     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->activeStorage->createCollection($collection);
         $collection_storage->deleteAll($name . '.');
     }
     $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
     if (is_dir($schema_dir)) {
         // Refresh the schema cache if uninstalling an extension that provides
         // configuration schema.
         $this->typedConfigManager->clearCachedDefinitions();
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE)
 {
     if (!isset($this->languages)) {
         // Prepopulate the language list with the default language to keep things
         // working even if we have no configuration.
         $default = $this->getDefaultLanguage();
         $this->languages = array($default->getId() => $default);
         // Retrieve the list of languages defined in configuration.
         $prefix = 'language.entity.';
         $config_ids = $this->configFactory->listAll($prefix);
         // Instantiate languages from config objects.
         $weight = 0;
         foreach ($this->configFactory->loadMultiple($config_ids) as $config) {
             $data = $config->get();
             $langcode = $data['id'];
             // Initialize default property so callers have an easy reference and can
             // save the same object without data loss.
             $data['default'] = $langcode == $default->getId();
             $data['name'] = $data['label'];
             $this->languages[$langcode] = new Language($data);
             $weight = max(array($weight, $this->languages[$langcode]->getWeight()));
         }
         // Add locked languages, they will be filtered later if needed.
         $this->languages += $this->getDefaultLockedLanguages($weight);
         // Sort the language list by weight then title.
         Language::sort($this->languages);
     }
     return parent::getLanguages($flags);
 }
コード例 #5
0
ファイル: ConfigInstaller.php プロジェクト: dmyerson/d8ecs
 /**
  * Finds default configuration with unmet dependencies.
  *
  * @param array $enabled_extensions
  *   A list of all the currently enabled modules and themes.
  *
  * @return array
  *   List of configuration that has unmet dependencies
  */
 protected function findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, StorageInterface $profile_storage = NULL)
 {
     $config_to_create = $this->getConfigToCreate($storage, StorageInterface::DEFAULT_COLLECTION, '', $profile_storage);
     $all_config = array_merge($this->configFactory->listAll(), array_keys($config_to_create));
     return array_filter(array_keys($config_to_create), function ($config_name) use($enabled_extensions, $all_config, $config_to_create) {
         return !$this->validateDependencies($config_name, $config_to_create[$config_name], $enabled_extensions, $all_config);
     });
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function getAllDefinedLanguages()
 {
     // Get list of all configured languages.
     $languages = [];
     // See Drupal\language\ConfigurableLanguageManager::getLanguages() for details
     $predefined = LanguageManager::getStandardLanguageList();
     foreach ($predefined as $key => $value) {
         $languages[$key] = new TranslatableMarkup($value[0]);
     }
     $config_ids = $this->configFactory->listAll('language.entity.');
     foreach ($this->configFactory->loadMultiple($config_ids) as $config) {
         $data = $config->get();
         $languages[$data['id']] = new TranslatableMarkup($data['label']);
     }
     asort($languages);
     return $languages;
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function uninstall($type, $name)
 {
     // Remove all dependent configuration entities.
     $extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
     // Give config entities a chance to become independent of the entities we
     // are going to delete.
     foreach ($extension_dependent_entities as $entity) {
         $entity_dependencies = $entity->getDependencies();
         if (empty($entity_dependencies)) {
             // No dependent entities nothing to do.
             continue;
         }
         // Work out if any of the entity's dependencies are going to be affected
         // by the uninstall.
         $affected_dependencies = array('entity' => array(), 'module' => array(), 'theme' => array());
         if (isset($entity_dependencies['entity'])) {
             foreach ($extension_dependent_entities as $extension_dependent_entity) {
                 if (in_array($extension_dependent_entity->getConfigDependencyName(), $entity_dependencies['entity'])) {
                     $affected_dependencies['entity'][] = $extension_dependent_entity;
                 }
             }
         }
         // Check if the extension being uninstalled is a dependency of the entity.
         if (isset($entity_dependencies[$type]) && in_array($name, $entity_dependencies[$type])) {
             $affected_dependencies[$type] = array($name);
         }
         // Inform the entity.
         $entity->onDependencyRemoval($affected_dependencies);
     }
     // Recalculate the dependencies, some config entities may have fixed their
     // dependencies on the to-be-removed entities.
     $extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
     // Reverse the array to that entities are removed in the correct order of
     // dependence. For example, this ensures that fields are removed before
     // field storages.
     foreach (array_reverse($extension_dependent_entities) as $extension_dependent_entity) {
         $extension_dependent_entity->setUninstalling(TRUE);
         $extension_dependent_entity->delete();
     }
     $config_names = $this->configFactory->listAll($name . '.');
     foreach ($config_names as $config_name) {
         $this->configFactory->get($config_name)->delete();
     }
     // Remove any matching configuration from collections.
     foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
         $collection_storage = $this->activeStorage->createCollection($collection);
         $collection_storage->deleteAll($name . '.');
     }
     $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
     if (is_dir($schema_dir)) {
         // Refresh the schema cache if uninstalling an extension that provides
         // configuration schema.
         $this->typedConfigManager->clearCachedDefinitions();
     }
 }
コード例 #8
0
 public function get($entity = NULL, $bundle = NULL)
 {
     if ($entity && $bundle) {
         $permission = 'Administer content types';
         if (!$this->currentUser->hasPermission($permission)) {
             throw new AccessDeniedHttpException();
         }
         $entity_view_display = $this->entityManager->getDefinition('entity_view_display');
         $config_prefix = $entity_view_display->getConfigPrefix();
         $list = $this->configFactory->listAll($config_prefix . '.' . $entity . '.' . $bundle . '.');
         $view_modes = array();
         foreach ($list as $view_mode) {
             $view_mode_machine_id = str_replace($config_prefix . '.', '', $view_mode);
             list(, , $view_mode_label) = explode('.', $view_mode_machine_id);
             $view_modes[$view_mode_machine_id] = $view_mode_label;
         }
         if (!empty($view_modes)) {
             return new ResourceResponse($view_modes);
         }
         throw new NotFoundHttpException(t('Views modes for @entity and @bundle were not found', array('@entity' => $entity, '@bundle' => $bundle)));
     }
     throw new HttpException(t('Entity or Bundle weren\'t provided'));
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 protected function doLoadMultiple(array $ids = NULL)
 {
     $prefix = $this->getPrefix();
     // Get the names of the configuration entities we are going to load.
     if ($ids === NULL) {
         $names = $this->configFactory->listAll($prefix);
     } else {
         $names = array();
         foreach ($ids as $id) {
             // Add the prefix to the ID to serve as the configuration object name.
             $names[] = $prefix . $id;
         }
     }
     // Load all of the configuration entities.
     /** @var \Drupal\Core\Config\Config[] $configs */
     $configs = [];
     $records = [];
     foreach ($this->configFactory->loadMultiple($names) as $config) {
         $id = $config->get($this->idKey);
         $records[$id] = $this->overrideFree ? $config->getOriginal(NULL, FALSE) : $config->get();
         $configs[$id] = $config;
     }
     $entities = $this->mapFromStorageRecords($records, $configs);
     // Config entities wrap config objects, and therefore they need to inherit
     // the cacheability metadata of config objects (to ensure e.g. additional
     // cacheability metadata added by config overrides is not lost).
     foreach ($entities as $id => $entity) {
         // But rather than simply inheriting all cacheability metadata of config
         // objects, we need to make sure the self-referring cache tag that is
         // present on Config objects is not added to the Config entity. It must be
         // removed for 3 reasons:
         // 1. When renaming/duplicating a Config entity, the cache tag of the
         //    original config object would remain present, which would be wrong.
         // 2. Some Config entities choose to not use the cache tag that the under-
         //    lying Config object provides by default (For performance and
         //    cacheability reasons it may not make sense to have a unique cache
         //    tag for every Config entity. The DateFormat Config entity specifies
         //    the 'rendered' cache tag for example, because A) date formats are
         //    changed extremely rarely, so invalidating all render cache items is
         //    fine, B) it means fewer cache tags per page.).
         // 3. Fewer cache tags is better for performance.
         $self_referring_cache_tag = ['config:' . $configs[$id]->getName()];
         $config_cacheability = CacheableMetadata::createFromObject($configs[$id]);
         $config_cacheability->setCacheTags(array_diff($config_cacheability->getCacheTags(), $self_referring_cache_tag));
         $entity->addCacheableDependency($config_cacheability);
     }
     return $entities;
 }
コード例 #10
0
 /**
  * Returns entity (form) displays for the current entity display type.
  *
  * @return array
  *   An array holding entity displays or entity form displays.
  */
 protected function getDisplays()
 {
     $load_ids = array();
     $display_entity_type = $this->getDisplayType();
     $entity_type = $this->entityManager->getDefinition($display_entity_type);
     $config_prefix = $entity_type->getConfigPrefix();
     $ids = $this->configFactory->listAll($config_prefix . '.' . $this->entity_type . '.' . $this->bundle . '.');
     foreach ($ids as $id) {
         $config_id = str_replace($config_prefix . '.', '', $id);
         list(, , $display_mode) = explode('.', $config_id);
         if ($display_mode != 'default') {
             $load_ids[] = $config_id;
         }
     }
     return entity_load_multiple($display_entity_type, $load_ids);
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 protected function doLoadMultiple(array $ids = NULL)
 {
     $prefix = $this->getPrefix();
     // Get the names of the configuration entities we are going to load.
     if ($ids === NULL) {
         $names = $this->configFactory->listAll($prefix);
     } else {
         $names = array();
         foreach ($ids as $id) {
             // Add the prefix to the ID to serve as the configuration object name.
             $names[] = $prefix . $id;
         }
     }
     // Load all of the configuration entities.
     $records = array();
     foreach ($this->configFactory->loadMultiple($names) as $config) {
         $records[$config->get($this->idKey)] = $this->overrideFree ? $config->getOriginal(NULL, FALSE) : $config->get();
     }
     return $this->mapFromStorageRecords($records);
 }
コード例 #12
0
ファイル: Query.php プロジェクト: brstde/gap1
 /**
  * Loads the config records to examine for the query.
  *
  * @return array
  *   Config records keyed by entity IDs.
  */
 protected function loadRecords()
 {
     $prefix = $this->entityType->getConfigPrefix() . '.';
     $prefix_length = strlen($prefix);
     // Search the conditions for restrictions on entity IDs.
     $ids = array();
     if ($this->condition->getConjunction() == 'AND') {
         foreach ($this->condition->conditions() as $condition) {
             if (is_string($condition['field']) && $condition['field'] == $this->entityType->getKey('id')) {
                 $operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '=');
                 if ($operator == '=') {
                     $ids = array($condition['value']);
                 } elseif ($operator == 'IN') {
                     $ids = $condition['value'];
                 }
                 // We stop at the first restricting condition on ID. In the (weird)
                 // case where there are additional restricting conditions, results
                 // will be eliminated when the conditions are checked on the loaded
                 // records.
                 if ($ids) {
                     break;
                 }
             }
         }
     }
     // If there are conditions restricting config ID, we can narrow the list of
     // records to load and parse.
     if ($ids) {
         $names = array_map(function ($id) use($prefix) {
             return $prefix . $id;
         }, $ids);
     } else {
         $names = $this->configFactory->listAll($prefix);
     }
     // Load the corresponding records.
     $records = array();
     foreach ($this->configFactory->loadMultiple($names) as $config) {
         $records[substr($config->getName(), $prefix_length)] = $config->get();
     }
     return $records;
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE)
 {
     // If a config override is set, cache using that language's ID.
     if ($override_language = $this->getConfigOverrideLanguage()) {
         $static_cache_id = $override_language->getId();
     } else {
         $static_cache_id = $this->getCurrentLanguage()->getId();
     }
     if (!isset($this->languages[$static_cache_id][$flags])) {
         // Initialize the language list with the default language and default
         // locked languages. These cannot be removed. This serves as a fallback
         // list if this method is invoked while the language module is installed
         // and the configuration entities for languages are not yet fully
         // imported.
         $default = $this->getDefaultLanguage();
         $languages = array($default->getId() => $default);
         $languages += $this->getDefaultLockedLanguages($default->getWeight());
         // Load configurable languages on top of the defaults. Ideally this could
         // use the entity API to load and instantiate ConfigurableLanguage
         // objects. However the entity API depends on the language system, so that
         // would result in infinite loops. We use the configuration system
         // directly and instantiate runtime Language objects. When language
         // entities are imported those cover the default and locked languages, so
         // site-specific configuration will prevail over the fallback values.
         // Having them in the array already ensures if this is invoked in the
         // middle of importing language configuration entities, the defaults are
         // always present.
         $config_ids = $this->configFactory->listAll('language.entity.');
         foreach ($this->configFactory->loadMultiple($config_ids) as $config) {
             $data = $config->get();
             $data['name'] = $data['label'];
             $languages[$data['id']] = new Language($data);
         }
         Language::sort($languages);
         // Filter the full list of languages based on the value of $flags.
         $this->languages[$static_cache_id][$flags] = $this->filterLanguages($languages, $flags);
     }
     return $this->languages[$static_cache_id][$flags];
 }
コード例 #14
0
ファイル: BaseMapping.php プロジェクト: globalbility/flags
 /**
  * Creates new instance of BaseMapping class.
  *
  * @param ConfigFactoryInterface $config
  */
 public function __construct(ConfigFactoryInterface $config)
 {
     $ids = $config->listAll($this->getConfigKey());
     $this->config = $config->loadMultiple($ids);
 }
コード例 #15
0
ファイル: Query.php プロジェクト: 318io/318-io
 /**
  * Loads the config records to examine for the query.
  *
  * @return array
  *   Config records keyed by entity IDs.
  */
 protected function loadRecords()
 {
     $prefix = $this->entityType->getConfigPrefix() . '.';
     $prefix_length = strlen($prefix);
     // Search the conditions for restrictions on configuration object names.
     $names = FALSE;
     $id_condition = NULL;
     $id_key = $this->entityType->getKey('id');
     if ($this->condition->getConjunction() == 'AND') {
         $lookup_keys = $this->entityType->getLookupKeys();
         $conditions = $this->condition->conditions();
         foreach ($conditions as $condition_key => $condition) {
             $operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '=');
             if (is_string($condition['field']) && ($operator == 'IN' || $operator == '=')) {
                 // Special case ID lookups.
                 if ($condition['field'] == $id_key) {
                     $ids = (array) $condition['value'];
                     $names = array_map(function ($id) use($prefix) {
                         return $prefix . $id;
                     }, $ids);
                 } elseif (in_array($condition['field'], $lookup_keys)) {
                     // If we don't find anything then there are no matches. No point in
                     // listing anything.
                     $names = array();
                     $keys = (array) $condition['value'];
                     $keys = array_map(function ($value) use($condition) {
                         return $condition['field'] . ':' . $value;
                     }, $keys);
                     foreach ($this->getConfigKeyStore()->getMultiple($keys) as $list) {
                         $names = array_merge($names, $list);
                     }
                 }
             } elseif (!$id_condition && $condition['field'] == $id_key) {
                 $id_condition = $condition;
             }
             // We stop at the first restricting condition on name. In the case where
             // there are additional restricting conditions, results will be
             // eliminated when the conditions are checked on the loaded records.
             if ($names !== FALSE) {
                 // If the condition has been responsible for narrowing the list of
                 // configuration to check there is no point in checking it further.
                 unset($conditions[$condition_key]);
                 break;
             }
         }
     }
     // If no restrictions on IDs were found, we need to parse all records.
     if ($names === FALSE) {
         $names = $this->configFactory->listAll($prefix);
     }
     // In case we have an ID condition, try to narrow down the list of config
     // objects to load.
     if ($id_condition && !empty($names)) {
         $value = $id_condition['value'];
         $filter = NULL;
         switch ($id_condition['operator']) {
             case '<>':
                 $filter = function ($name) use($value, $prefix_length) {
                     $id = substr($name, $prefix_length);
                     return $id !== $value;
                 };
                 break;
             case 'STARTS_WITH':
                 $filter = function ($name) use($value, $prefix_length) {
                     $id = substr($name, $prefix_length);
                     return strpos($id, $value) === 0;
                 };
                 break;
             case 'CONTAINS':
                 $filter = function ($name) use($value, $prefix_length) {
                     $id = substr($name, $prefix_length);
                     return strpos($id, $value) !== FALSE;
                 };
                 break;
             case 'ENDS_WITH':
                 $filter = function ($name) use($value, $prefix_length) {
                     $id = substr($name, $prefix_length);
                     return strrpos($id, $value) === strlen($id) - strlen($value);
                 };
                 break;
         }
         if ($filter) {
             $names = array_filter($names, $filter);
         }
     }
     // Load the corresponding records.
     $records = array();
     foreach ($this->configFactory->loadMultiple($names) as $config) {
         $records[substr($config->getName(), $prefix_length)] = $config->get();
     }
     return $records;
 }