本文整理汇总了PHP中Drupal\Core\Entity\EntityStorageInterface::load方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityStorageInterface::load方法的具体用法?PHP EntityStorageInterface::load怎么用?PHP EntityStorageInterface::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityStorageInterface
的用法示例。
在下文中一共展示了EntityStorageInterface::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* {@inheritdoc}
*
* Set the block plugin id.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
if (is_array($value)) {
list($module, $delta) = $value;
switch ($module) {
case 'aggregator':
list($type, $id) = explode('-', $delta);
if ($type == 'feed') {
return 'aggregator_feed_block';
}
break;
case 'menu':
return "system_menu_block:{$delta}";
case 'block':
if ($this->blockContentStorage) {
$block_id = $this->migrationPlugin->transform($delta, $migrate_executable, $row, $destination_property);
if ($block_id) {
return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
}
}
break;
default:
break;
}
} else {
return $value;
}
}
示例2: resolveCurrencyLocale
/**
* {@inheritdoc}
*/
public function resolveCurrencyLocale($language_type = LanguageInterface::TYPE_CONTENT)
{
if (empty($this->currencyLocales[$language_type])) {
$currency_locale = NULL;
$language_code = $this->languageManager->getCurrentLanguage($language_type)->getId();
// Try this request's country code.
$country_code = $this->eventDispatcher->resolveCountryCode();
if ($country_code) {
$currency_locale = $this->currencyLocaleStorage->load($language_code . '_' . $country_code);
}
// Try the site's default country code.
if (!$currency_locale) {
$country_code = $this->configFactory->get('system.data')->get('country.default');
if ($country_code) {
$currency_locale = $this->currencyLocaleStorage->load($language_code . '_' . $country_code);
}
}
// Try the Currency default.
if (!$currency_locale) {
$currency_locale = $this->currencyLocaleStorage->load($this::DEFAULT_LOCALE);
}
if ($currency_locale) {
$this->currencyLocales[$language_type] = $currency_locale;
} else {
throw new \RuntimeException(sprintf('The currency locale for %s could not be loaded.', $this::DEFAULT_LOCALE));
}
}
return $this->currencyLocales[$language_type];
}
示例3: transform
/**
* {@inheritdoc}
*
* Set the block plugin id.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
if (is_array($value)) {
list($module, $delta) = $value;
switch ($module) {
case 'aggregator':
list($type, $id) = explode('-', $delta);
if ($type == 'category') {
// @TODO skip row.
// throw new MigrateSkipRowException();
}
$value = 'aggregator_feed_block';
break;
case 'menu':
$value = "system_menu_block:{$delta}";
break;
case 'block':
if ($this->blockContentStorage) {
$block_ids = $this->processPluginManager->createInstance('migration', array('migration' => 'd6_custom_block'), $this->migration)->transform($delta, $migrate_executable, $row, $destination_property);
$value = 'block_content:' . $this->blockContentStorage->load($block_ids[0])->uuid();
} else {
throw new MigrateSkipRowException();
}
break;
default:
throw new MigrateSkipRowException();
}
}
return $value;
}
示例4: import
/**
* {@inheritdoc}
*/
public function import($currencyCode) {
if ($existingEntity = $this->storage->load($currencyCode)) {
// Pretend the currency was just imported.
return $existingEntity;
}
$defaultLangcode = $this->languageManager->getDefaultLanguage()->getId();
$currency = $this->externalRepository->get($currencyCode, $defaultLangcode, 'en');
$values = [
'langcode' => $defaultLangcode,
'currencyCode' => $currency->getCurrencyCode(),
'name' => $currency->getName(),
'numericCode' => $currency->getNumericCode(),
'symbol' => $currency->getSymbol(),
'fractionDigits' => $currency->getFractionDigits(),
];
$entity = $this->storage->create($values);
$entity->trustData()->save();
if ($this->languageManager->isMultilingual()) {
// Import translations for any additional languages the site has.
$languages = $this->languageManager->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
$languages = array_diff_key($languages, [$defaultLangcode => $defaultLangcode]);
$langcodes = array_map(function ($language) {
return $language->getId();
}, $languages);
$this->importEntityTranslations($entity, $langcodes);
}
return $entity;
}
示例5: match
/**
* {@inheritdoc}
*/
public function match(AddressInterface $address)
{
$zone = $this->zoneStorage->load($this->configuration['zone']);
if ($zone) {
return $zone->match($address);
}
}
示例6: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['to']['#markup'] = $this->stateStorage->load($entity->getToState())->label();
$row['label'] = $entity->label();
$row['roles']['#markup'] = implode(', ', user_role_names(FALSE, 'use ' . $entity->id() . ' transition'));
return $row + parent::buildRow($entity);
}
示例7: transform
/**
* {@inheritdoc}
*
* Find the parent link GUID.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
$parent_id = array_shift($value);
if (!$parent_id) {
// Top level item.
return '';
}
try {
$already_migrated_id = $this->migrationPlugin->transform($parent_id, $migrate_executable, $row, $destination_property);
if ($already_migrated_id && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
return $link->getPluginId();
}
} catch (MigrateSkipRowException $e) {
}
if (isset($value[1])) {
list($menu_name, $parent_link_path) = $value;
$url = Url::fromUserInput("/{$parent_link_path}");
if ($url->isRouted()) {
$links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name);
if (count($links) == 1) {
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = reset($links);
return $link->getPluginId();
}
}
}
throw new MigrateSkipRowException();
}
示例8: purlCheckNodeContext
/**
* Checks if a node's type requires a redirect.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event to process.
*/
public function purlCheckNodeContext(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher_interface)
{
$route_options = $this->routeMatch->getRouteObject()->getOptions();
$isAdminRoute = array_key_exists('_admin_route', $route_options) && $route_options['_admin_route'];
if (!$isAdminRoute && ($matched = $this->matchedModifiers->getMatched() && ($entity = $this->routeMatch->getParameter('node')))) {
$node_type = $this->entityStorage->load($entity->bundle());
$purl_settings = $node_type->getThirdPartySettings('purl');
if (!isset($purl_settings['keep_context']) || !$purl_settings['keep_context']) {
$url = \Drupal\Core\Url::fromRoute($this->routeMatch->getRouteName(), $this->routeMatch->getRawParameters()->all(), ['host' => Settings::get('purl_base_domain'), 'absolute' => TRUE]);
try {
$redirect_response = new TrustedRedirectResponse($url->toString());
$redirect_response->getCacheableMetadata()->setCacheMaxAge(0);
$modifiers = $event->getRequest()->attributes->get('purl.matched_modifiers', []);
$new_event = new ExitedContextEvent($event->getRequest(), $redirect_response, $this->routeMatch, $modifiers);
$dispatcher_interface->dispatch(PurlEvents::EXITED_CONTEXT, $new_event);
$event->setResponse($new_event->getResponse());
return;
} catch (RedirectLoopException $e) {
\Drupal::logger('redirect')->warning($e->getMessage());
$response = new Response();
$response->setStatusCode(503);
$response->setContent('Service unavailable');
$event->setResponse($response);
return;
}
}
}
}
示例9: render
/**
* {@inheritdoc}
*/
public function render($empty = FALSE)
{
if (!empty($this->options['view_to_insert'])) {
list($view_name, $display_id) = explode(':', $this->options['view_to_insert']);
$view = $this->viewStorage->load($view_name)->getExecutable();
if (empty($view) || !$view->access($display_id)) {
return array();
}
$view->setDisplay($display_id);
// Avoid recursion
$view->parent_views += $this->view->parent_views;
$view->parent_views[] = "{$view_name}:{$display_id}";
// Check if the view is part of the parent views of this view
$search = "{$view_name}:{$display_id}";
if (in_array($search, $this->view->parent_views)) {
drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
} else {
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
$output = $view->preview($display_id, $this->view->args);
} else {
$output = $view->preview($display_id);
}
$this->isEmpty = $view->display_handler->outputIsEmpty();
return $output;
}
}
return array();
}
示例10:
/**
* Render node type as human readable name, unless using machine_name option.
*/
function render_name($data, $values)
{
if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
$type = $this->nodeTypeStorage->load($data);
return $type ? $this->t($this->sanitizeValue($type->label())) : '';
}
return $this->sanitizeValue($data);
}
示例11: importTaxType
/**
* Imports a single tax type.
*
* @param \CommerceGuys\Tax\Model\TaxTypeInterface $taxType
* The tax type.
*/
protected function importTaxType(ExternalTaxTypeInterface $taxType)
{
if ($this->taxTypeStorage->load($taxType->getId())) {
return;
}
$values = ['id' => $taxType->getId(), 'name' => $this->t($taxType->getName()), 'compound' => $taxType->isCompound(), 'displayInclusive' => $taxType->isDisplayInclusive(), 'roundingMode' => $taxType->getRoundingMode(), 'tag' => $taxType->getTag(), 'rates' => array_keys($taxType->getRates())];
return $this->taxTypeStorage->create($values);
}
示例12: processItem
/**
* {@inheritdoc}
*/
public function processItem($data)
{
/** @var NodeInterface $node */
$node = $this->nodeStorage->load($data->nid);
if (!$node->isPublished() && $node instanceof NodeInterface) {
return $this->publishNode($node);
}
}
示例13: eventType
/**
* {@inheritdoc}
*/
function eventType($entity_type, $bundle)
{
$ids = $this->eventTypeStorage->getQuery()->condition('entity_type', $entity_type, '=')->condition('bundle', $bundle, '=')->execute();
if ($ids) {
return $this->eventTypeStorage->load(reset($ids));
}
return NULL;
}
示例14: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/** @var ModerationStateTransitionInterface $entity */
$row['label'] = $entity->label();
$row['id']['#markup'] = $entity->id();
$row['from']['#markup'] = $this->stateStorage->load($entity->getFromState())->label();
$row['to']['#markup'] = $this->stateStorage->load($entity->getToState())->label();
return $row + parent::buildRow($entity);
}
示例15: testDefaultComponents
/**
* Tests Rules default components.
*/
public function testDefaultComponents()
{
$config_entity = $this->storage->load('rules_test_default_component');
$user = $this->entityTypeManager->getStorage('user')->create(['mail' => 'test@example.com']);
$config_entity->getComponent()->setContextValue('user', $user)->execute();
// Test that the action was executed correctly.
$messages = drupal_get_messages();
$message_string = isset($messages['status'][0]) ? (string) $messages['status'][0] : NULL;
$this->assertEquals($message_string, 'test@example.com');
}