Exemplo n.º 1
0
  /**
   * @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;
  }
Exemplo n.º 2
0
 /**
  * {@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);
 }
 /**
  * {@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;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * {@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;
 }
Exemplo n.º 5
0
 /**
  * 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([], []));
 }
Exemplo n.º 6
0
 /**
  * {@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();
 }
 /**
  * {@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];
 }
Exemplo n.º 8
0
 /**
  * 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));
 }
Exemplo n.º 9
0
 /**
  * {@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');
 }
Exemplo n.º 10
0
 /**
  * {@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;
 }
Exemplo n.º 11
0
 /**
  * {@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;
 }
Exemplo n.º 12
0
 /**
  * {@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;
 }
Exemplo n.º 13
0
 /**
  * {@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;
     }
 }
Exemplo n.º 14
0
 /**
  * {@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();
 }
Exemplo n.º 15
0
 /**
  * {@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);
     }
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function match(AddressInterface $address)
 {
     $zone = $this->zoneStorage->load($this->configuration['zone']);
     if ($zone) {
         return $zone->match($address);
     }
 }
Exemplo n.º 17
0
 /**
  * {@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;
 }
 /**
  * Tests ConfigurableEventHandlerEntityBundle.
  *
  * Test that rules are triggered correctly based upon the fully qualified
  * event name as well as the base event name.
  *
  * @todo Add integrity check that node.field_integer is detected by Rules.
  */
 public function testConfigurableEventHandler()
 {
     // Create rule1 with the 'rules_entity_presave:node--page' event.
     $rule1 = $this->expressionManager->createRule();
     $rule1->addAction('rules_test_log', ContextConfig::create()->map('message', 'node.field_integer.0.value'));
     $config_entity1 = $this->storage->create(['id' => 'test_rule1']);
     $config_entity1->set('events', [['event_name' => 'rules_entity_presave:node--page']]);
     $config_entity1->set('expression', $rule1->getConfiguration());
     $config_entity1->save();
     // Create rule2 with the 'rules_entity_presave:node' event.
     $rule2 = $this->expressionManager->createRule();
     $rule2->addAction('rules_test_log', ContextConfig::create()->map('message', 'node.field_integer.1.value'));
     $config_entity2 = $this->storage->create(['id' => 'test_rule2']);
     $config_entity2->set('events', [['event_name' => 'rules_entity_presave:node']]);
     $config_entity2->set('expression', $rule2->getConfiguration());
     $config_entity2->save();
     // The logger instance has changed, refresh it.
     $this->logger = $this->container->get('logger.channel.rules');
     // Add node.field_integer.0.value to rules log message, read result.
     $this->node->field_integer->setValue(['0' => 11, '1' => 22]);
     // Trigger node save.
     $entity_type_id = $this->node->getEntityTypeId();
     $event = new EntityEvent($this->node, [$entity_type_id => $this->node]);
     $event_dispatcher = \Drupal::service('event_dispatcher');
     $event_dispatcher->dispatch("rules_entity_presave:{$entity_type_id}", $event);
     // Test that the action in the rule1 logged node value.
     $this->assertRulesLogEntryExists(11, 1);
     // Test that the action in the rule2 logged node value.
     $this->assertRulesLogEntryExists(22, 0);
 }
 /**
  * {@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;
 }
Exemplo n.º 20
0
 /**
  * {@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;
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function getVisibleBlocksPerRegion(array &$cacheable_metadata = [])
 {
     $active_theme = $this->themeManager->getActiveTheme();
     // Build an array of the region names in the right order.
     $empty = array_fill_keys($active_theme->getRegions(), array());
     $full = array();
     foreach ($this->blockStorage->loadByProperties(array('theme' => $active_theme->getName())) as $block_id => $block) {
         /** @var \Drupal\block\BlockInterface $block */
         $access = $block->access('view', NULL, TRUE);
         $region = $block->getRegion();
         if (!isset($cacheable_metadata[$region])) {
             $cacheable_metadata[$region] = CacheableMetadata::createFromObject($access);
         } else {
             $cacheable_metadata[$region] = $cacheable_metadata[$region]->merge(CacheableMetadata::createFromObject($access));
         }
         // Set the contexts on the block before checking access.
         if ($access->isAllowed()) {
             $full[$region][$block_id] = $block;
         }
     }
     // Merge it with the actual values to maintain the region ordering.
     $assignments = array_intersect_key(array_merge($empty, $full), $empty);
     foreach ($assignments as &$assignment) {
         // Suppress errors because PHPUnit will indirectly modify the contents,
         // triggering https://bugs.php.net/bug.php?id=50688.
         @uasort($assignment, 'Drupal\\block\\Entity\\Block::sort');
     }
     return $assignments;
 }
Exemplo n.º 22
0
 /**
  * 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;
             }
         }
     }
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $derivatives = [];
     foreach ($this->storage->loadMultiple() as $feed_type) {
         $derivatives[$feed_type->id()] = $base_plugin_definition;
     }
     return $derivatives;
 }
Exemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function processItem($data)
 {
     /** @var NodeInterface $node */
     $node = $this->nodeStorage->load($data->nid);
     if (!$node->isPublished() && $node instanceof NodeInterface) {
         return $this->publishNode($node);
     }
 }
 /**
  * @covers ::execute
  */
 public function testExecute()
 {
     $currency = $this->getMock(CurrencyInterface::class);
     $this->currencyStorage->expects($this->once())->method('create')->with(array())->willReturn($currency);
     $form = $this->getMock(EntityFormInterface::class);
     $this->entityFormBuilder->expects($this->once())->method('getForm')->with($currency)->willReturn($form);
     $this->assertSame($form, $this->sut->execute());
 }
Exemplo n.º 26
0
 /**
  * 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);
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, $node_revision = NULL)
 {
     $this->revision = $this->nodeStorage->loadRevision($node_revision);
     $form = parent::buildForm($form, $form_state);
     // @todo Convert to getCancelRoute() after http://drupal.org/node/1863906.
     $form['actions']['cancel']['#href'] = 'node/' . $this->revision->id() . '/revisions';
     return $form;
 }
 /**
  * @covers ::execute
  */
 public function testExecute()
 {
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $this->paymentStatusStorage->expects($this->once())->method('create')->willReturn($payment_status);
     $form = $this->getMock(FormInterface::class);
     $this->entityFormBuilder->expects($this->once())->method('getForm')->with($payment_status)->willReturn($form);
     $this->assertSame($form, $this->sut->execute());
 }
Exemplo n.º 29
0
 /**
  * {@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;
 }
Exemplo n.º 30
0
 /**
  * {@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;
     });
 }