本文整理汇总了PHP中Drupal\Core\Entity\EntityStorageInterface类的典型用法代码示例。如果您正苦于以下问题:PHP EntityStorageInterface类的具体用法?PHP EntityStorageInterface怎么用?PHP EntityStorageInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityStorageInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMultiple
/**
* {@inheritdoc}
*/
public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = NULL)
{
/** @var \Drupal\migrate\Entity\MigrationInterface $bundle_migration */
$bundle_migration = $storage->load('d6_taxonomy_vocabulary');
$migrate_executable = new MigrateExecutable($bundle_migration, new MigrateMessage());
$process = array_intersect_key($bundle_migration->get('process'), $bundle_migration->getDestinationPlugin()->getIds());
$migrations = array();
$vid_map = array();
foreach ($bundle_migration->getIdMap() as $key => $value) {
$old_vid = unserialize($key)['sourceid1'];
$new_vid = $value['destid1'];
$vid_map[$old_vid] = $new_vid;
}
foreach ($bundle_migration->getSourcePlugin()->getIterator() as $source_row) {
$row = new Row($source_row, $source_row);
$migrate_executable->processRow($row, $process);
$old_vid = $source_row['vid'];
$new_vid = $row->getDestinationProperty('vid');
$vid_map[$old_vid] = $new_vid;
}
foreach ($vid_map as $old_vid => $new_vid) {
$values = $this->migration->toArray();
$migration_id = $this->migration->id() . ':' . $old_vid;
$values['id'] = $migration_id;
$values['source']['vid'] = $old_vid;
$values['process'][$new_vid] = 'tid';
$migrations[$migration_id] = $storage->create($values);
}
return $migrations;
}
示例2: loadMultiple
/**
* {@inheritdoc}
*/
public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = NULL)
{
if (isset($this->configuration['bundle_migration'])) {
/** @var \Drupal\migrate\Entity\MigrationInterface $bundle_migration */
$bundle_migration = $storage->load($this->configuration['bundle_migration']);
$source_id = array_keys($bundle_migration->getSourcePlugin()->getIds())[0];
$this->bundles = array();
foreach ($bundle_migration->getSourcePlugin()->getIterator() as $row) {
$this->bundles[] = $row[$source_id];
}
} else {
// This entity type has no bundles ('user', 'feed', etc).
$this->bundles = array($this->migration->getSourcePlugin()->entityTypeId());
}
$sub_ids_to_load = isset($sub_ids) ? array_intersect($this->bundles, $sub_ids) : $this->bundles;
$migrations = array();
foreach ($sub_ids_to_load as $id) {
$values = $this->migration->toArray();
$values['id'] = $this->migration->id() . ':' . $id;
$values['source']['bundle'] = $id;
/** @var \Drupal\migrate_drupal\Entity\MigrationInterface $migration */
$migration = $storage->create($values);
if ($migration->getSourcePlugin()->checkRequirements()) {
$fields = array_keys($migration->getSourcePlugin()->fields());
$migration->process += array_combine($fields, $fields);
$migrations[$migration->id()] = $migration;
}
}
return $migrations;
}
示例3: activeList
/**
* @param $active_group_ids
*
* @return array
*/
public function activeList($active_group_ids) {
$active_group_ids = explode(',', $active_group_ids);
/** @var \Drupal\block_visibility_groups\Entity\BlockVisibilityGroup[] $groups */
$groups = $this->storage->loadMultiple($active_group_ids);
$edit_links = [];
foreach ($groups as $group) {
$edit_links[] = [
'#type' => 'container',
'edit' => [
'#type' => 'link',
'#title' => $group->label(),
'#url' => $group->urlInfo('edit-form'),
'#suffix' => ' - ',
],
'manage' => [
'#type' => 'link',
'#title' => t('Manage Blocks'),
'#url' => Url::fromRoute('block.admin_display_theme', [
'theme' => \Drupal::theme()->getActiveTheme()->getName(),
],
[
'query' => ['block_visibility_group' => $group->id()],
]
),
],
];
}
return $edit_links;
}
示例4: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
/** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */
$product_type = $this->entity;
$variation_types = $this->variationTypeStorage->loadMultiple();
$variation_types = array_map(function ($variation_type) {
return $variation_type->label();
}, $variation_types);
// Create an empty product to get the default status value.
// @todo Clean up once https://www.drupal.org/node/2318187 is fixed.
if ($this->operation == 'add') {
$product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->uuid()]);
} else {
$product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->id()]);
}
$form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $product_type->label(), '#required' => TRUE];
$form['id'] = ['#type' => 'machine_name', '#default_value' => $product_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_product\\Entity\\ProductType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
$form['description'] = ['#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $product_type->getDescription()];
$form['variationType'] = ['#type' => 'select', '#title' => $this->t('Product variation type'), '#default_value' => $product_type->getVariationType(), '#options' => $variation_types, '#required' => TRUE];
$form['product_status'] = ['#type' => 'checkbox', '#title' => t('Publish new products of this type by default.'), '#default_value' => $product->isPublished()];
if ($this->moduleHandler->moduleExists('language')) {
$form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
$form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_product', 'bundle' => $product_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_product', $product_type->id())];
$form['#submit'][] = 'language_configuration_element_submit';
}
return $this->protectBundleIdElement($form);
}
示例5: alterRoutes
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection)
{
foreach ($this->entityStorage->loadMultiple() as $entity_id => $entity) {
/** @var \Drupal\page_manager\PageInterface $entity */
// If the page is disabled skip making a route for it.
if (!$entity->status() || !$entity->getVariants()) {
continue;
}
// Prepare the values that need to be altered for an existing page.
$parameters = ['page_manager_page_variant' => ['type' => 'entity:page_variant'], 'page_manager_page' => ['type' => 'entity:page']];
$requirements = [];
if ($route_name = $this->findPageRouteName($entity, $collection)) {
$this->cacheTagsInvalidator->invalidateTags(["page_manager_route_name:{$route_name}"]);
$collection_route = $collection->get($route_name);
$path = $collection_route->getPath();
$parameters += $collection_route->getOption('parameters') ?: [];
$requirements += $collection_route->getRequirements();
$collection->remove($route_name);
} else {
$route_name = "page_manager.page_view_{$entity_id}";
$path = $entity->getPath();
$requirements['_entity_access'] = 'page_manager_page.view';
}
$page_id = $entity->id();
$first = TRUE;
foreach ($entity->getVariants() as $variant_id => $variant) {
// Construct and add a new route.
$route = new Route($path, ['_entity_view' => 'page_manager_page_variant', '_title' => $entity->label(), 'page_manager_page_variant' => $variant_id, 'page_manager_page' => $page_id, 'base_route_name' => $route_name], $requirements, ['parameters' => $parameters, '_admin_route' => $entity->usesAdminTheme()]);
$collection->add($first ? $route_name : $route_name . '_' . $variant_id, $route);
$first = FALSE;
}
}
}
示例6: getDerivativeDefinitions
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition)
{
// Check all Views for block displays.
foreach ($this->viewStorage->loadMultiple() as $view) {
// Do not return results for disabled views.
if (!$view->status()) {
continue;
}
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
// Add a block plugin definition for each block display.
if (isset($display) && !empty($display->definition['uses_hook_block'])) {
$delta = $view->id() . '-' . $display->display['id'];
$desc = $display->getOption('block_description');
if (empty($desc)) {
if ($display->display['display_title'] == $display->definition['title']) {
$desc = t('!view', array('!view' => $view->label()));
} else {
$desc = t('!view: !display', array('!view' => $view->label(), '!display' => $display->display['display_title']));
}
}
$this->derivatives[$delta] = array('category' => $display->getOption('block_category'), 'admin_label' => $desc, 'config_dependencies' => array('entity' => array($view->getConfigDependencyName())));
$this->derivatives[$delta] += $base_plugin_definition;
}
}
}
return $this->derivatives;
}
示例7: testImportEntityLoadFailure
/**
* Test row skipping when we can't get an entity to save.
*
* @covers ::import
* @expectedException \Drupal\migrate\MigrateException
* @expectedExceptionMessage Unable to get entity
*/
public function testImportEntityLoadFailure()
{
$bundles = [];
$destination = new EntityTestDestination([], '', [], $this->migration->reveal(), $this->storage->reveal(), $bundles, $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
$destination->setEntity(FALSE);
$destination->import(new Row([], []));
}
示例8: 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();
}
示例9: 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];
}
示例10: testGetUniqueMachineName
/**
* Tests the unique machine name generator.
*
* @see \Drupal\block\BlockForm::getUniqueMachineName()
*/
public function testGetUniqueMachineName()
{
$blocks = array();
$blocks['test'] = $this->getBlockMockWithMachineName('test');
$blocks['other_test'] = $this->getBlockMockWithMachineName('other_test');
$blocks['other_test_1'] = $this->getBlockMockWithMachineName('other_test');
$blocks['other_test_2'] = $this->getBlockMockWithMachineName('other_test');
$query = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
$query->expects($this->exactly(5))->method('condition')->will($this->returnValue($query));
$query->expects($this->exactly(5))->method('execute')->will($this->returnValue(array('test', 'other_test', 'other_test_1', 'other_test_2')));
$this->storage->expects($this->exactly(5))->method('getQuery')->will($this->returnValue($query));
$block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler);
// Ensure that the block with just one other instance gets the next available
// name suggestion.
$this->assertEquals('test_2', $block_form_controller->getUniqueMachineName($blocks['test']));
// Ensure that the block with already three instances (_0, _1, _2) gets the
// 4th available name.
$this->assertEquals('other_test_3', $block_form_controller->getUniqueMachineName($blocks['other_test']));
$this->assertEquals('other_test_3', $block_form_controller->getUniqueMachineName($blocks['other_test_1']));
$this->assertEquals('other_test_3', $block_form_controller->getUniqueMachineName($blocks['other_test_2']));
// Ensure that a block without an instance yet gets the suggestion as
// unique machine name.
$last_block = $this->getBlockMockWithMachineName('last_test');
$this->assertEquals('last_test', $block_form_controller->getUniqueMachineName($last_block));
}
示例11: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// TODO: Change the autogenerated stub
$condition_plugin_manager = $this->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface');
$condition_plugin_manager->expects($this->any())->method('getDefinitions')->will($this->returnValue(array()));
$container = new ContainerBuilder();
$container->set('plugin.manager.condition', $condition_plugin_manager);
\Drupal::setContainer($container);
$this->executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage'])->getMock();
$this->executable->expects($this->any())->method('setDisplay')->with('block_1')->will($this->returnValue(TRUE));
$this->executable->expects($this->any())->method('getShowAdminLinks')->willReturn(FALSE);
$this->executable->display_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->setMethods(NULL)->getMock();
$this->view = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock();
$this->view->expects($this->any())->method('id')->willReturn('test_view');
$this->executable->storage = $this->view;
$this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock();
$this->executableFactory->expects($this->any())->method('get')->with($this->view)->will($this->returnValue($this->executable));
$this->displayHandler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->getMock();
$this->displayHandler->expects($this->any())->method('blockSettings')->willReturn([]);
$this->displayHandler->expects($this->any())->method('getPluginId')->willReturn('block');
$this->executable->display_handler = $this->displayHandler;
$this->storage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock();
$this->storage->expects($this->any())->method('load')->with('test_view')->will($this->returnValue($this->view));
$this->account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
}
示例12: getDerivativeDefinitions
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition)
{
// Check all Views for block displays.
foreach ($this->viewStorage->loadMultiple() as $view) {
// Do not return results for disabled views.
if (!$view->status()) {
continue;
}
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
// Add a block plugin definition for each block display.
if (isset($display) && !empty($display->definition['uses_hook_block'])) {
$delta = $view->id() . '-' . $display->display['id'];
$admin_label = $display->getOption('block_description');
if (empty($admin_label)) {
if ($display->display['display_title'] == $display->definition['title']) {
$admin_label = $view->label();
} else {
// Allow translators to control the punctuation. Plugin
// definitions get cached, so use TranslatableMarkup() instead of
// t() to avoid double escaping when $admin_label is rendered
// during requests that use the cached definition.
$admin_label = new TranslatableMarkup('@view: @display', ['@view' => $view->label(), '@display' => $display->display['display_title']]);
}
}
$this->derivatives[$delta] = array('category' => $display->getOption('block_category'), 'admin_label' => $admin_label, 'config_dependencies' => array('config' => array($view->getConfigDependencyName())));
$this->derivatives[$delta] += $base_plugin_definition;
}
}
}
return $this->derivatives;
}
示例13: 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;
}
}
示例14: 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();
}
示例15: alterRoutes
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection)
{
foreach ($this->entityStorage->loadMultiple() as $entity_id => $entity) {
/** @var $entity \Drupal\page_manager\PageInterface */
// If the page is disabled skip making a route for it.
if (!$entity->status() || $entity->isFallbackPage()) {
continue;
}
// Prepare a route name to use if this is a custom page.
$route_name = "page_manager.page_view_{$entity_id}";
// Prepare the values that need to be altered for an existing page.
$path = $entity->getPath();
$parameters = ['page_manager_page' => ['type' => 'entity:page']];
// Loop through all existing routes to see if this is overriding a route.
foreach ($collection->all() as $name => $collection_route) {
// Find all paths which match the path of the current display.
$route_path = RouteCompiler::getPathWithoutDefaults($collection_route);
$route_path = RouteCompiler::getPatternOutline($route_path);
if ($path == $route_path) {
// Adjust the path to translate %placeholders to {slugs}.
$path = $collection_route->getPath();
// Merge in any route parameter definitions.
$parameters += $collection_route->getOption('parameters') ?: [];
// Update the route name this will be added to.
$route_name = $name;
// Remove the existing route.
$collection->remove($route_name);
break;
}
}
// Construct an add a new route.
$route = new Route($path, ['_entity_view' => 'page_manager_page', 'page_manager_page' => $entity_id, '_title' => $entity->label()], ['_entity_access' => 'page_manager_page.view'], ['parameters' => $parameters, '_admin_route' => $entity->usesAdminTheme()]);
$collection->add($route_name, $route);
}
}