当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityTypeManagerInterface::getStorage方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityTypeManagerInterface::getStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTypeManagerInterface::getStorage方法的具体用法?PHP EntityTypeManagerInterface::getStorage怎么用?PHP EntityTypeManagerInterface::getStorage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityTypeManagerInterface的用法示例。


在下文中一共展示了EntityTypeManagerInterface::getStorage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkAccess

 protected function checkAccess(ContentEntityInterface $entity, AccountInterface $account, $operation = 'view')
 {
     $entity_type = $entity->getEntityType();
     $entity_type_id = $entity->getEntityTypeId();
     $entity_access = $this->entityTypeManager->getAccessControlHandler($entity_type_id);
     /** @var \Drupal\Core\Entity\EntityStorageInterface $entity_storage */
     $entity_storage = $this->entityTypeManager->getStorage($entity_type_id);
     $map = ['view' => "view all {$entity_type_id} revisions", 'list' => "view all {$entity_type_id} revisions", 'update' => "revert all {$entity_type_id} revisions", 'delete' => "delete all {$entity_type_id} revisions"];
     $bundle = $entity->bundle();
     $type_map = ['view' => "view {$entity_type_id} {$bundle} revisions", 'list' => "view {$entity_type_id} {$bundle} revisions", 'update' => "revert {$entity_type_id} {$bundle} revisions", 'delete' => "delete {$entity_type_id} {$bundle} revisions"];
     if (!$entity || !isset($map[$operation]) || !isset($type_map[$operation])) {
         // If there was no node to check against, or the $op was not one of the
         // supported ones, we return access denied.
         return FALSE;
     }
     // Statically cache access by revision ID, language code, user account ID,
     // and operation.
     $langcode = $entity->language()->getId();
     $cid = $entity->getRevisionId() . ':' . $langcode . ':' . $account->id() . ':' . $operation;
     if (!isset($this->accessCache[$cid])) {
         // Perform basic permission checks first.
         if (!$account->hasPermission($map[$operation]) && !$account->hasPermission($type_map[$operation]) && !$account->hasPermission('administer nodes')) {
             $this->accessCache[$cid] = FALSE;
             return FALSE;
         }
         if (($admin_permission = $entity_type->getAdminPermission()) && $account->hasPermission($admin_permission)) {
             $this->accessCache[$cid] = TRUE;
         } else {
             // First check the access to the default revision and finally, if the
             // node passed in is not the default revision then access to that, too.
             $this->accessCache[$cid] = $entity_access->access($entity_storage->load($entity->id()), $operation, $account) && ($entity->isDefaultRevision() || $entity_access->access($entity, $operation, $account));
         }
     }
     return $this->accessCache[$cid];
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:35,代码来源:EntityRevisionRouteAccessChecker.php

示例2: getDescription

 /**
  * {@inheritdoc}
  */
 public function getDescription()
 {
     $locked = $this->tempStore->getMetadata($this->entity->id());
     $account = $this->entityTypeManager->getStorage('user')->load($locked->owner);
     $username = array('#theme' => 'username', '#account' => $account);
     return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', array('@user' => $this->renderer->render($username)));
 }
开发者ID:curveagency,项目名称:intranet,代码行数:10,代码来源:IndexBreakLockForm.php

示例3: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     // --module option
     $module = $input->getOption('module');
     if (!$module) {
         // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
         $module = $this->moduleQuestion($io);
         $input->setOption('module', $module);
     }
     // view-id argument
     $viewId = $input->getArgument('view-id');
     if (!$viewId) {
         $views = $this->entityTypeManager->getStorage('view')->loadMultiple();
         $viewList = [];
         foreach ($views as $view) {
             $viewList[$view->get('id')] = $view->get('label');
         }
         $viewId = $io->choiceNoList($this->trans('commands.config.export.view.questions.view'), $viewList);
         $input->setArgument('view-id', $viewId);
     }
     $optionalConfig = $input->getOption('optional-config');
     if (!$optionalConfig) {
         $optionalConfig = $io->confirm($this->trans('commands.config.export.view.questions.optional-config'), true);
         $input->setOption('optional-config', $optionalConfig);
     }
     $includeModuleDependencies = $input->getOption('include-module-dependencies');
     if (!$includeModuleDependencies) {
         $includeModuleDependencies = $io->confirm($this->trans('commands.config.export.view.questions.include-module-dependencies'), true);
         $input->setOption('include-module-dependencies', $includeModuleDependencies);
     }
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:35,代码来源:ExportViewCommand.php

示例4: onRulesEvent

 /**
  * Reacts on the given event and invokes configured reaction rules.
  *
  * @param \Symfony\Component\EventDispatcher\Event $event
  *   The event object containing context for the event.
  * @param string $event_name
  *   The event name.
  */
 public function onRulesEvent(Event $event, $event_name)
 {
     // Load reaction rule config entities by $event_name.
     $storage = $this->entityTypeManager->getStorage('rules_reaction_rule');
     // @todo Only load active reaction rules here.
     $configs = $storage->loadByProperties(['event' => $event_name]);
     // Set up an execution state with the event context.
     $event_definition = $this->eventManager->getDefinition($event_name);
     $state = ExecutionState::create();
     foreach ($event_definition['context'] as $context_name => $context_definition) {
         // If this is a GenericEvent get the context for the rule from the event
         // arguments.
         if ($event instanceof GenericEvent) {
             $value = $event->getArgument($context_name);
         } else {
             $value = $event->{$context_name};
         }
         $state->setVariable($context_name, $context_definition, $value);
     }
     // Loop over all rules and execute them.
     foreach ($configs as $config) {
         /** @var \Drupal\rules\Entity\ReactionRuleConfig $config */
         $config->getExpression()->executeWithState($state);
     }
     $state->autoSave();
 }
开发者ID:DrupalTV,项目名称:DrupalTV,代码行数:34,代码来源:GenericEventSubscriber.php

示例5: getDescription

 /**
  * {@inheritdoc}
  */
 public function getDescription()
 {
     $locked = $this->rulesUiHandler->getLockMetaData();
     $account = $this->entityTypeManager->getStorage('user')->load($locked->owner);
     $username = ['#theme' => 'username', '#account' => $account];
     return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', ['@user' => $this->renderer->render($username)]);
 }
开发者ID:Progressable,项目名称:openway8,代码行数:10,代码来源:BreakLockForm.php

示例6: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $styles = $input->getArgument('styles');
     $result = 0;
     $imageStyle = $this->entityTypeManager->getStorage('image_style');
     $stylesNames = [];
     if (in_array('all', $styles)) {
         $styles = $imageStyle->loadMultiple();
         foreach ($styles as $style) {
             $stylesNames[] = $style->get('name');
         }
         $styles = $stylesNames;
     }
     foreach ($styles as $style) {
         try {
             $io->info(sprintf($this->trans('commands.image.styles.flush.messages.executing-flush'), $style));
             $imageStyle->load($style)->flush();
         } catch (\Exception $e) {
             watchdog_exception('image', $e);
             $io->error($e->getMessage());
             $result = 1;
         }
     }
     $io->success($this->trans('commands.image.styles.flush.messages.success'));
     return $result;
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:30,代码来源:StylesFlushCommand.php

示例7: __construct

 /**
  * Constructs the target plugin.
  */
 public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $current_user);
     $this->paragraphStorage = $entity_type_manager->getStorage('paragraph');
     $this->paragraphsTypeStorage = $entity_type_manager->getStorage('paragraphs_type');
     $this->fieldConfigStorage = $entity_type_manager->getStorage('field_config');
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:10,代码来源:Paragraphs.php

示例8: __construct

 /**
  * Constructs a new TaxTypeImporter.
  *
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
  *   The entity type manager.
  * @param string
  *   The tax types folder of definitions.
  */
 public function __construct(EntityTypeManagerInterface $entityTypeManager, TranslationInterface $stringTranslation, $taxTypesFolder = NULL) {
   $this->taxTypeStorage = $entityTypeManager->getStorage('commerce_tax_type');
   $this->taxRateStorage = $entityTypeManager->getStorage('commerce_tax_rate');
   $this->taxRateAmountStorage = $entityTypeManager->getStorage('commerce_tax_rate_amount');
   $this->stringTranslation = $stringTranslation;
   $this->taxTypeRepository = new TaxTypeRepository($taxTypesFolder);
 }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:15,代码来源:TaxTypeImporter.php

示例9: access

 /**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, RdfInterface $rdf_entity, $operation = 'view')
 {
     $graph = $route->getOption('graph_name');
     $entity_type_id = $route->getOption('entity_type_id');
     $storage = $this->entityManager->getStorage($entity_type_id);
     if (!$storage instanceof RdfEntitySparqlStorage) {
         throw new \Exception('Storage not supported.');
     }
     // The active graph is the published graph. It is handled by the default
     // operation handler.
     // @todo: getActiveGraph is not the default. We should load from settings.
     $default_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), 'default');
     $requested_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), $graph);
     if ($requested_graph == $default_graph) {
         return AccessResult::neutral();
     }
     $active_graph_type = $storage->getRequestGraphs($rdf_entity->id());
     // Check if there is an entity saved in the passed graph.
     $storage->setRequestGraphs($rdf_entity->id(), [$graph]);
     $entity = $storage->load($rdf_entity->id());
     // Restore active graph.
     $storage->setRequestGraphs($rdf_entity->id(), $active_graph_type);
     // @todo: When the requested graph is the only one and it is not the
     // default, it is loaded in the default view, so maybe there is no need
     // to also show a separate tab.
     return AccessResult::allowedIf($entity && $this->checkAccess($rdf_entity, $route, $account, $operation, $graph))->cachePerPermissions()->addCacheableDependency($rdf_entity);
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:30,代码来源:RdfGraphAccessCheck.php

示例10: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /* @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $bundle */
     $bundle = $form_state->getFormObject()->getEntity();
     $form['enable_moderation_state'] = ['#type' => 'checkbox', '#title' => $this->t('Enable moderation states.'), '#description' => $this->t('Content of this type must transition through moderation states in order to be published.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'enabled', FALSE)];
     // Add a special message when moderation is being disabled.
     if ($bundle->getThirdPartySetting('content_moderation', 'enabled', FALSE)) {
         $form['enable_moderation_state_note'] = ['#type' => 'item', '#description' => $this->t('After disabling moderation, any existing forward drafts will be accessible via the "Revisions" tab.'), '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => FALSE]]]];
     }
     $states = $this->entityTypeManager->getStorage('moderation_state')->loadMultiple();
     $label = function (ModerationState $state) {
         return $state->label();
     };
     $options_published = array_map($label, array_filter($states, function (ModerationState $state) {
         return $state->isPublishedState();
     }));
     $options_unpublished = array_map($label, array_filter($states, function (ModerationState $state) {
         return !$state->isPublishedState();
     }));
     $form['allowed_moderation_states_unpublished'] = ['#type' => 'checkboxes', '#title' => $this->t('Allowed moderation states (Unpublished)'), '#description' => $this->t('The allowed unpublished moderation states this content-type can be assigned.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($options_unpublished)), '#options' => $options_unpublished, '#required' => TRUE, '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     $form['allowed_moderation_states_published'] = ['#type' => 'checkboxes', '#title' => $this->t('Allowed moderation states (Published)'), '#description' => $this->t('The allowed published moderation states this content-type can be assigned.'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', array_keys($options_published)), '#options' => $options_published, '#required' => TRUE, '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     // The key of the array needs to be a user-facing string so we have to fully
     // render the translatable string to a real string, or else PHP errors on an
     // object used as an array key.
     $options = [$this->t('Unpublished')->render() => $options_unpublished, $this->t('Published')->render() => $options_published];
     $form['default_moderation_state'] = ['#type' => 'select', '#title' => $this->t('Default moderation state'), '#options' => $options, '#description' => $this->t('Select the moderation state for new content'), '#default_value' => $bundle->getThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'), '#states' => ['visible' => [':input[name=enable_moderation_state]' => ['checked' => TRUE]]]];
     $form['#entity_builders'][] = [$this, 'formBuilderCallback'];
     return parent::form($form, $form_state);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:32,代码来源:BundleModerationConfigurationForm.php

示例11: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $moduleHandler = $this->moduleHandler;
     $moduleHandler->loadInclude('locale', 'inc', 'locale.translation');
     $moduleHandler->loadInclude('locale', 'module');
     $language = $input->getArgument('language');
     $languagesObjects = locale_translatable_language_list();
     $languages = $this->site->getStandardLanguages();
     if (isset($languagesObjects[$language])) {
         $languageEntity = $languagesObjects[$language];
     } elseif (array_search($language, $languages)) {
         $langcode = array_search($language, $languages);
         $languageEntity = $languagesObjects[$langcode];
     } else {
         $io->error(sprintf($this->trans('commands.locale.language.delete.messages.invalid-language'), $language));
         return 1;
     }
     try {
         $configurable_language_storage = $this->entityTypeManager->getStorage('configurable_language');
         $configurable_language_storage->load($languageEntity->getId())->delete();
         $io->info(sprintf($this->trans('commands.locale.language.delete.messages.language-deleted-successfully'), $languageEntity->getName()));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     return 0;
 }
开发者ID:ranqiangjun,项目名称:DrupalConsole,代码行数:28,代码来源:LanguageDeleteCommand.php

示例12: deleteExistingTerms

 /**
  * Destroy all existing terms before import
  * @param $vid
  * @param $io
  */
 private function deleteExistingTerms($vid = null, DrupalStyle $io)
 {
     //Load the vid
     $termStorage = $this->entityTypeManager->getStorage('taxonomy_term');
     $vocabularies = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->loadMultiple();
     if ($vid !== 'all') {
         $vid = [$vid];
     } else {
         $vid = array_keys($vocabularies);
     }
     foreach ($vid as $item) {
         if (!isset($vocabularies[$item])) {
             $io->error("Invalid vid: {$item}.");
         }
         $vocabulary = $vocabularies[$item];
         $terms = $termStorage->loadTree($vocabulary->id());
         foreach ($terms as $term) {
             $treal = $termStorage->load($term->tid);
             if ($treal !== null) {
                 $io->info("Deleting '{$term->name}' and all translations.");
                 $treal->delete();
             }
         }
     }
 }
开发者ID:ranqiangjun,项目名称:DrupalConsole,代码行数:30,代码来源:DeleteTermCommand.php

示例13: getConfigNames

 protected function getConfigNames($config_type)
 {
     // For a given entity type, load all entities.
     if ($config_type && $config_type !== 'system.simple') {
         $entity_storage = $this->entityTypeManager->getStorage($config_type);
         foreach ($entity_storage->loadMultiple() as $entity) {
             $entity_id = $entity->id();
             $label = $entity->label() ?: $entity_id;
             $names[$entity_id] = $label;
         }
     } else {
         // Gather the config entity prefixes.
         $config_prefixes = array_map(function ($definition) {
             return $definition->getConfigPrefix() . '.';
         }, $this->definitions);
         // Find all config, and then filter our anything matching a config prefix.
         $names = $this->configStorage->listAll();
         $names = array_combine($names, $names);
         foreach ($names as $config_name) {
             foreach ($config_prefixes as $config_prefix) {
                 if (strpos($config_name, $config_prefix) === 0) {
                     unset($names[$config_name]);
                 }
             }
         }
     }
     return $names;
 }
开发者ID:ranqiangjun,项目名称:DrupalConsole,代码行数:28,代码来源:ExportSingleCommand.php

示例14: build

  /**
   * {@inheritdoc}
   */
  public function build($entity_type_id, $entity_id, $flag_id) {
    $entity = $this->entityTypeManager->getStorage($entity_type_id)->load($entity_id);
    $flag = $this->flagService->getFlagById($flag_id);

    $link_type_plugin = $flag->getLinkTypePlugin();
    $link = $link_type_plugin->getLink($flag, $entity);
    return $link;
  }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:11,代码来源:FlagLinkBuilder.php

示例15: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->pageVariantStorage = $this->prophesize(ConfigEntityStorageInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getStorage('page_variant')->willReturn($this->pageVariantStorage);
     $this->currentPath = $this->prophesize(CurrentPathStack::class);
     $this->routeFilter = new VariantRouteFilter($this->entityTypeManager->reveal(), $this->currentPath->reveal());
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:11,代码来源:VariantRouteFilterTest.php


注:本文中的Drupal\Core\Entity\EntityTypeManagerInterface::getStorage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。