/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $book_nids = array(); $links = array(Link::createFromRoute($this->t('Home'), '<front>')); $book = $route_match->getParameter('node')->book; $depth = 1; // We skip the current node. while (!empty($book['p' . ($depth + 1)])) { $book_nids[] = $book['p' . $depth]; $depth++; } $parent_books = $this->nodeStorage->loadMultiple($book_nids); if (count($parent_books) > 0) { $depth = 1; while (!empty($book['p' . ($depth + 1)])) { if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) { if ($parent_book->access('view', $this->account)) { $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id())); } } $depth++; } } return $links; }
/** * {@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); } }
/** * {@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; }
/** * {@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); }
/** * @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; }
/** * {@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; }
/** * {@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; } } }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $book_nids = array(); $breadcrumb = new Breadcrumb(); $links = array(Link::createFromRoute($this->t('Home'), '<front>')); $book = $route_match->getParameter('node')->book; $depth = 1; // We skip the current node. while (!empty($book['p' . ($depth + 1)])) { $book_nids[] = $book['p' . $depth]; $depth++; } $parent_books = $this->nodeStorage->loadMultiple($book_nids); if (count($parent_books) > 0) { $depth = 1; while (!empty($book['p' . ($depth + 1)])) { if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) { $access = $parent_book->access('view', $this->account, TRUE); $breadcrumb->addCacheableDependency($access); if ($access->isAllowed()) { $breadcrumb->addCacheableDependency($parent_book); $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id())); } } $depth++; } } $breadcrumb->setLinks($links); $breadcrumb->addCacheContexts(['route.book_navigation']); return $breadcrumb; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $derivatives = []; foreach ($this->storage->loadMultiple() as $feed_type) { $derivatives[$feed_type->id()] = $base_plugin_definition; } return $derivatives; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->menuStorage->loadMultiple() as $menu => $entity) { $this->derivatives[$menu] = $base_plugin_definition; $this->derivatives[$menu]['admin_label'] = $entity->label(); $this->derivatives[$menu]['config_dependencies']['config'] = array($entity->getConfigDependencyName()); } return $this->derivatives; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityStorage->loadMultiple() as $blocktabs => $entity) { //drupal_set_message('123:' . $blocktabs); $this->derivatives[$blocktabs] = $base_plugin_definition; $this->derivatives[$blocktabs]['admin_label'] = 'Blocktabs:' . $entity->label(); $this->derivatives[$blocktabs]['config_dependencies']['config'] = array($entity->getConfigDependencyName()); } return $this->derivatives; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { /** @var \Drupal\payment\Entity\PaymentStatusInterface[] $statuses */ $statuses = $this->paymentStatusStorage->loadMultiple(); foreach ($statuses as $status) { $this->derivatives[$status->id()] = array('description' => $status->getDescription(), 'label' => $status->label(), 'parent_id' => $status->getParentId()) + $base_plugin_definition; } return parent::getDerivativeDefinitions($base_plugin_definition); }
/** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); $entity_type = $this->getEntityType(); // Filter the actions to only include those for this entity type. $this->actions = array_filter($this->actionStorage->loadMultiple(), function ($action) use($entity_type) { return $action->getType() == $entity_type; }); }
/** * Displays add custom block links for available types. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. * * @return array * A render array for a list of the custom block types that can be added or * if there is only one custom block type defined for the site, the function * returns the custom block add page for that custom block type. */ public function add(Request $request) { $types = $this->blockContentTypeStorage->loadMultiple(); if ($types && count($types) == 1) { $type = reset($types); return $this->addForm($type, $request); } return array('#theme' => 'block_content_add_list', '#content' => $types); }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { // Check all menu blocks for block displays. foreach ($this->menuBlockStorage->loadMultiple() as $menu_block) { $delta = $menu_block->id(); $this->derivatives[$delta] = array('category' => 'menu block', 'admin_label' => $menu_block->getAdminBlockTitle()); $this->derivatives[$delta] += $base_plugin_definition; } return $this->derivatives; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $options = array(); $node_types = $this->entityStorage->loadMultiple(); foreach ($node_types as $type) { $options[$type->type] = $type->name; } $form['bundles'] = array('#title' => $this->t('Node types'), '#type' => 'checkboxes', '#options' => $options, '#default_value' => $this->configuration['bundles']); return parent::buildConfigurationForm($form, $form_state); }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $links = array(); /** @var $taxonomy_menus \Drupal\taxonomy_menu\TaxonomyMenuInterface[] */ $taxonomy_menus = $this->taxonomyMenuStorage->loadMultiple(); foreach ($taxonomy_menus as $taxonomy_menu) { $links = array_merge($links, $taxonomy_menu->getLinks($base_plugin_definition)); } return $links; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $rules_components = $this->storage->loadMultiple(); foreach ($rules_components as $rules_component) { $component_config = $rules_component->get('component'); $expression_definition = $this->expressionManager->getDefinition($component_config['expression']['id']); $this->derivatives[$rules_component->id()] = ['label' => $this->t('@expression_type: @label', ['@expression_type' => $expression_definition['label'], '@label' => $rules_component->label()]), 'category' => $this->t('Components'), 'component_id' => $rules_component->id(), 'context' => $rules_component->getContextDefinitions(), 'provides' => $rules_component->getProvidedContextDefinitions()] + $base_plugin_definition; } return $this->derivatives; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $block_contents = $this->blockContentStorage->loadMultiple(); /** @var $block_content \Drupal\block_content\Entity\BlockContent */ foreach ($block_contents as $block_content) { $this->derivatives[$block_content->uuid()] = $base_plugin_definition; $this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label(); $this->derivatives[$block_content->uuid()]['config_dependencies']['content'] = array($block_content->getConfigDependencyName()); } return parent::getDerivativeDefinitions($base_plugin_definition); }
/** * Dynamically set permissions for entity browsers with routes. */ public function permissions() { $permissions = []; /** @var \Drupal\entity_browser\EntityBrowserInterface[] $browsers */ $browsers = $this->browserStorage->loadMultiple(); foreach ($browsers as $browser) { if ($browser->route()) { $permissions['access ' . $browser->id() . ' entity browser pages'] = array('title' => $this->translationManager->translate('Access @name pages', array('@name' => $browser->label())), 'description' => $this->translationManager->translate('Access pages that %browser uses to operate.', array('%browser' => $browser->label()))); } } return $permissions; }
/** * Returns TRUE if destination value exists for provided migrations. * * @param array $value * @param $migration_name * * @return bool */ protected function destinationIdExists($value, $migration_name) { $migrations = $this->migrationStorage->loadMultiple([$migration_name]); /** @var MigrationInterface $migration */ foreach ($migrations as $migration_id => $migration) { // If destination ID is found, return TRUE. if ($destination_ids = $migration->getIdMap()->lookupDestinationID([$value])) { return TRUE; } } return FALSE; }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { // @see buildConfigurationForm(). $form['node_count'] = array('#title' => t('Node count'), '#type' => 'textfield', '#default_value' => $this->configuration['node_count'], '#description' => $this->t('Number of items to display')); $options = array(); $node_types = $this->entityStorage->loadMultiple(); foreach ($node_types as $type) { $options[$type->id()] = $type->label(); } $form['node_bundles'] = array('#title' => $this->t('Node types'), '#type' => 'checkboxes', '#options' => $options, '#default_value' => $this->configuration['node_bundles']); return $form; }
/** * Get all active groups. * * @return \Drupal\block_visibility_groups\Entity\BlockVisibilityGroup[] */ public function getActiveGroups() { $active_groups = []; /** @var BlockVisibilityGroup $group */ foreach ($this->group_storage->loadMultiple() as $id => $group) { /** @var \Drupal\block_visibility_groups\Plugin\Condition\ConditionGroup $condition ; */ $condition = $this->condition_manager->createInstance('condition_group', ['block_visibility_group' => $id]); if ($condition->evaluate()) { $active_groups[$id] = $group; } } return $active_groups; }
/** * {@inheritdoc} */ public function getImportableTaxTypes() { $importableTaxTypes = $this->taxTypeRepository->getAll(); $importedTaxTypes = $this->taxTypeStorage->loadMultiple(); // Remove any already imported tax types. foreach ($importedTaxTypes as $taxType) { if (isset($importableTaxTypes[$taxType->getId()])) { unset($importableTaxTypes[$taxType->getId()]); } } return $importableTaxTypes; }
/** * Displays add custom block links for available types. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request object. * * @return array * A render array for a list of the custom block types that can be added or * if there is only one custom block type defined for the site, the function * returns the custom block add page for that custom block type. */ public function add(Request $request) { $types = $this->blockContentTypeStorage->loadMultiple(); if ($types && count($types) == 1) { $type = reset($types); return $this->addForm($type, $request); } if (count($types) === 0) { return array('#markup' => $this->t('You have not created any block types yet. Go to the <a href=":url">block type creation page</a> to add a new block type.', [':url' => Url::fromRoute('block_content.type_add')->toString()])); } return array('#theme' => 'block_content_add_list', '#content' => $types); }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $currency_codes = []; foreach ($items as $delta => $item) { $currency_codes[] = $item->currency_code; } $currencies = $this->currencyStorage->loadMultiple($currency_codes); $elements = []; foreach ($items as $delta => $item) { $elements[$delta] = ['#theme' => 'commerce_price_plain', '#amount' => $item->amount, '#currency' => $currencies[$item->currency_code], '#cache' => ['contexts' => ['languages:' . LanguageInterface::TYPE_INTERFACE, 'country']]]; } return $elements; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { /** @var \Drupal\payment\Entity\PaymentMethodConfigurationInterface[] $payment_methods */ $payment_methods = $this->paymentMethodConfigurationStorage->loadMultiple(); foreach ($payment_methods as $payment_method) { if ($payment_method->getPluginId() == 'payment_basic') { /** @var \Drupal\payment\Plugin\Payment\MethodConfiguration\Basic $configuration_plugin */ $configuration_plugin = $this->paymentMethodConfigurationManager->createInstance($payment_method->getPluginId(), $payment_method->getPluginConfiguration()); $this->derivatives[$payment_method->id()] = array('id' => $base_plugin_definition['id'] . ':' . $payment_method->id(), 'active' => $payment_method->status(), 'label' => $configuration_plugin->getBrandLabel() ? $configuration_plugin->getBrandLabel() : $payment_method->label(), 'message_text' => $configuration_plugin->getMessageText(), 'message_text_format' => $configuration_plugin->getMessageTextFormat(), 'execute_status_id' => $configuration_plugin->getExecuteStatusId(), 'capture' => $configuration_plugin->getCapture(), 'capture_status_id' => $configuration_plugin->getCaptureStatusId(), 'refund' => $configuration_plugin->getRefund(), 'refund_status_id' => $configuration_plugin->getRefundStatusId()) + $base_plugin_definition; } } return $this->derivatives; }
/** * Dynamically defines each route added. * * @return RouteCollection */ public function routes() { $collection = new RouteCollection(); // Get all the empty page callbacks. $callbackRoutes = $this->emptyPageStorage->loadMultiple(); // Loop over all callbacks and create a new route for each callback. foreach ($callbackRoutes as $route) { // Route defaults. $defaults = array('_controller' => '\\Drupal\\empty_page\\Controller\\EmptyPageController::callback', '_title' => $route->getTitle()); // Route requirements. $requirements = array('_permission' => 'access content'); $collection->add('empty_page.' . $route->getName(), new Route($route->getPath(), $defaults, $requirements)); } return $collection; }
/** * {@inheritdoc} */ protected function generateElements(array $values) { $num = $values['num']; $kill = $values['kill']; $pass = $values['pass']; $age = $values['time_range']; $roles = array_filter($values['roles']); if ($kill) { $uids = $this->userStorage->getQuery()->condition('uid', 1, '>')->execute(); $users = $this->userStorage->loadMultiple($uids); $this->userStorage->delete($users); $this->setMessage($this->formatPlural(count($uids), '1 user deleted', '@count users deleted.')); } if ($num > 0) { $names = array(); while (count($names) < $num) { $name = $this->getRandom()->word(mt_rand(6, 12)); $names[$name] = ''; } if (empty($roles)) { $roles = array(DRUPAL_AUTHENTICATED_RID); } foreach ($names as $name => $value) { $account = $this->userStorage->create(array('uid' => NULL, 'name' => $name, 'pass' => $pass, 'mail' => $name . '@example.com', 'status' => 1, 'created' => REQUEST_TIME - mt_rand(0, $age), 'roles' => array_values($roles), 'devel_generate' => TRUE)); // Populate all fields with sample values. $this->populateFields($account); $account->save(); } } $this->setMessage($this->t('@num_users created.', array('@num_users' => $this->formatPlural($num, '1 user', '@count users')))); }
/** * Provides the list of accounts that can be used for the user switch. * * Inactive users are omitted from all of the following db selects. Users * with 'switch users' permission and anonymous user if include_anon property * is set to TRUE, are prioritized. * * @return \Drupal\core\Session\AccountInterface[] * List of accounts to be used for the switch. */ protected function getUsers() { $list_size = $this->configuration['list_size']; $include_anonymous = $this->configuration['include_anon']; $list_size = $include_anonymous ? $list_size - 1 : $list_size; // Users with 'switch users' permission are prioritized so // we try to load first users with this permission. $query = $this->userStorage->getQuery()->condition('uid', 0, '>')->condition('status', 0, '>')->sort('access', 'DESC')->range(0, $list_size); $roles = user_roles(TRUE, 'switch users'); if (!isset($roles[Role::AUTHENTICATED_ID])) { $query->condition('roles', array_keys($roles), 'IN'); } $user_ids = $query->execute(); // If we don't have enough users with 'switch users' permission, add // uids until we hit $list_size. if (count($user_ids) < $list_size) { $users = $this->userStorage->getQuery()->condition('uid', 0, '>')->condition('status', 0, '>')->condition('uid', array_keys($user_ids), 'NOT IN')->sort('access', 'DESC')->range(0, $list_size - count($user_ids))->execute(); $user_ids += $users; } $accounts = $this->userStorage->loadMultiple($user_ids); if ($include_anonymous) { $anonymous = new AnonymousUserSession(); $accounts[$anonymous->id()] = $anonymous; } uasort($accounts, 'static::sortUserList'); return $accounts; }