/**
  * {@inheritdoc}
  */
 public function save(array $link)
 {
     $link += array('access' => 1, 'status' => 1, 'status_override' => 0, 'lastmod' => 0, 'priority' => XMLSITEMAP_PRIORITY_DEFAULT, 'priority_override' => 0, 'changefreq' => 0, 'changecount' => 0, 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED);
     // Allow other modules to alter the link before saving.
     $this->moduleHandler->alter('xmlsitemap_link', $link);
     // Temporary validation checks.
     // @todo Remove in final?
     if ($link['priority'] < 0 || $link['priority'] > 1) {
         trigger_error(t('Invalid sitemap link priority %priority.<br />@link', array('%priority' => $link['priority'], '@link' => var_export($link, TRUE))), E_USER_ERROR);
     }
     if ($link['changecount'] < 0) {
         trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@link', array('@516928' => 'http://drupal.org/node/516928', '@link' => var_export($link, TRUE))), E_USER_ERROR);
         $link['changecount'] = 0;
     }
     // Check if this is a changed link and set the regenerate flag if necessary.
     if (!$this->state->get('xmlsitemap_regenerate_needed')) {
         $this->checkChangedLink($link, NULL, TRUE);
     }
     $queryStatus = \Drupal::database()->merge('xmlsitemap')->key(array('type' => $link['type'], 'id' => $link['id']))->fields(array('loc' => $link['loc'], 'subtype' => $link['subtype'], 'access' => $link['access'], 'status' => $link['status'], 'status_override' => $link['status_override'], 'lastmod' => $link['lastmod'], 'priority' => $link['priority'], 'priority_override' => $link['priority_override'], 'changefreq' => $link['changefreq'], 'changecount' => $link['changecount'], 'language' => $link['language']))->execute();
     switch ($queryStatus) {
         case Merge::STATUS_INSERT:
             $this->moduleHandler->invokeAll('xmlsitemap_link_insert', array($link));
             break;
         case Merge::STATUS_UPDATE:
             $this->moduleHandler->invokeAll('xmlsitemap_link_update', array($link));
             break;
     }
     return $link;
 }
 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     if ($this->mapping === NULL) {
         $mapping = $this->defaultMapping;
         // Allow modules to alter the default mapping.
         $this->moduleHandler->alter('file_mimetype_mapping', $mapping);
         $this->mapping = $mapping;
     }
     $extension = '';
     $file_parts = explode('.', drupal_basename($path));
     // Remove the first part: a full filename should not match an extension.
     array_shift($file_parts);
     // Iterate over the file parts, trying to find a match.
     // For my.awesome.image.jpeg, we try:
     //   - jpeg
     //   - image.jpeg, and
     //   - awesome.image.jpeg
     while ($additional_part = array_pop($file_parts)) {
         $extension = strtolower($additional_part . ($extension ? '.' . $extension : ''));
         if (isset($this->mapping['extensions'][$extension])) {
             return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
         }
     }
     return 'application/octet-stream';
 }
 /**
  * Get an array of country code => country name pairs, altered by alter hooks.
  *
  * @return array
  *   An array of country code => country name pairs.
  *
  * @see \Drupal\Core\Locale\CountryManager::getStandardList()
  */
 public function getList()
 {
     // Populate the country list if it is not already populated.
     if (!isset($this->countries)) {
         $this->countries = static::getStandardList();
         $this->moduleHandler->alter('countries', $this->countries);
     }
     return $this->countries;
 }
Esempio n. 4
0
 /**
  * Builds up all element information.
  */
 protected function buildInfo()
 {
     $info = $this->moduleHandler->invokeAll('element_info');
     foreach ($info as $element_type => $element) {
         $info[$element_type]['#type'] = $element_type;
     }
     // Allow modules to alter the element type defaults.
     $this->moduleHandler->alter('element_info', $info);
     return $info;
 }
 /**
  * {@inheritdoc}
  */
 public function getEnabledList()
 {
     $countries = $this->entityTypeManager->getStorage('uc_country')->loadByProperties(['status' => TRUE]);
     $country_names = [];
     foreach ($countries as $alpha_2 => $country) {
         $country_names[$alpha_2] = t($country->getName());
     }
     natcasesort($country_names);
     $this->moduleHandler->alter('countries', $country_names);
     return $country_names;
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function getEntityTypeMappings()
 {
     if (empty($this->entityMappings)) {
         foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $info) {
             $this->entityMappings[$entity_type] = $info->get('token_type') ?: $entity_type;
         }
         // Allow modules to alter the mapping array.
         $this->moduleHandler->alter('token_entity_mapping', $this->entityMappings);
     }
     return $this->entityMappings;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     $this->moduleHandler->getImplementations('entity_type_build')->willReturn([]);
     $this->moduleHandler->alter('entity_type', Argument::type('array'))->willReturn(NULL);
     $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);
     $this->translationManager = $this->prophesize(TranslationInterface::class);
     $this->entityTypeManager = new TestEntityTypeManager(new \ArrayObject(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal(), $this->translationManager->reveal(), $this->getClassResolverStub());
     $this->discovery = $this->prophesize(DiscoveryInterface::class);
     $this->entityTypeManager->setDiscovery($this->discovery->reveal());
 }
 /**
  * {@inheritdoc}
  */
 public function getLibrariesByExtension($extension)
 {
     if (!isset($this->libraryDefinitions[$extension])) {
         $libraries = $this->collector->get($extension);
         $this->libraryDefinitions[$extension] = [];
         foreach ($libraries as $name => $definition) {
             // Allow modules and themes to dynamically attach request and context
             // specific data for this library; e.g., localization.
             $library_name = "{$extension}/{$name}";
             $this->moduleHandler->alter('library', $definition, $library_name);
             $this->libraryDefinitions[$extension][$name] = $definition;
         }
     }
     return $this->libraryDefinitions[$extension];
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function getAllBundleInfo()
 {
     if (empty($this->bundleInfo)) {
         $langcode = $this->languageManager->getCurrentLanguage()->getId();
         if ($cache = $this->cacheGet("entity_bundle_info:{$langcode}")) {
             $this->bundleInfo = $cache->data;
         } else {
             $this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info');
             foreach ($this->entityTypeManager->getDefinitions() as $type => $entity_type) {
                 // First look for entity types that act as bundles for others, load them
                 // and add them as bundles.
                 if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
                     foreach ($this->entityTypeManager->getStorage($bundle_entity_type)->loadMultiple() as $entity) {
                         $this->bundleInfo[$type][$entity->id()]['label'] = $entity->label();
                     }
                 } elseif (!isset($this->bundleInfo[$type])) {
                     $this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel();
                 }
             }
             $this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo);
             $this->cacheSet("entity_bundle_info:{$langcode}", $this->bundleInfo, Cache::PERMANENT, ['entity_types', 'entity_bundles']);
         }
     }
     return $this->bundleInfo;
 }
 /**
  * Registers the tagged stream wrappers.
  *
  * Internal use only.
  */
 public function register()
 {
     $this->moduleHandler->alter('stream_wrappers', $this->info);
     foreach ($this->info as $scheme => $info) {
         $this->registerWrapper($scheme, $info['class'], $info['type']);
     }
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = array();
     $context = array('builder' => NULL);
     // Call the build method of registered breadcrumb builders,
     // until one of them returns an array.
     foreach ($this->getSortedBuilders() as $builder) {
         if (!$builder->applies($route_match)) {
             // The builder does not apply, so we continue with the other builders.
             continue;
         }
         $build = $builder->build($route_match);
         if (is_array($build)) {
             // The builder returned an array of breadcrumb links.
             $breadcrumb = $build;
             $context['builder'] = $builder;
             break;
         } else {
             throw new \UnexpectedValueException(SafeMarkup::format('Invalid breadcrumb returned by !class::build().', array('!class' => get_class($builder))));
         }
     }
     // Allow modules to alter the breadcrumb.
     $this->moduleHandler->alter('system_breadcrumb', $breadcrumb, $route_match, $context);
     // Fall back to an empty breadcrumb.
     return $breadcrumb;
 }
Esempio n. 12
0
 /**
  * Processes cron queues.
  */
 protected function processQueues()
 {
     // Grab the defined cron queues.
     $queues = $this->moduleHandler->invokeAll('queue_info');
     $this->moduleHandler->alter('queue_info', $queues);
     foreach ($queues as $queue_name => $info) {
         if (isset($info['cron'])) {
             // Make sure every queue exists. There is no harm in trying to recreate
             // an existing queue.
             $this->queueFactory->get($queue_name)->createQueue();
             $callback = $info['worker callback'];
             $end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15);
             $queue = $this->queueFactory->get($queue_name);
             while (time() < $end && ($item = $queue->claimItem())) {
                 try {
                     call_user_func_array($callback, array($item->data));
                     $queue->deleteItem($item);
                 } catch (SuspendQueueException $e) {
                     // If the worker indicates there is a problem with the whole queue,
                     // release the item and skip to the next queue.
                     $queue->releaseItem($item);
                     watchdog_exception('cron', $e);
                     // Skip to the next queue.
                     continue 2;
                 } catch (\Exception $e) {
                     // In case of any other kind of exception, log it and leave the item
                     // in the queue to be processed again later.
                     watchdog_exception('cron', $e);
                 }
             }
         }
     }
 }
 /**
  * Tests the getAllBundleInfo() method.
  *
  * @covers ::getAllBundleInfo
  */
 public function testGetAllBundleInfo()
 {
     $this->moduleHandler->invokeAll('entity_bundle_info')->willReturn([]);
     $this->moduleHandler->alter('entity_bundle_info', Argument::type('array'))->willReturn(NULL);
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->getLabel()->willReturn('Apple');
     $apple->getBundleOf()->willReturn(NULL);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->getLabel()->willReturn('Banana');
     $banana->getBundleOf()->willReturn(NULL);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $this->cacheBackend->get('entity_bundle_info:en')->willReturn(FALSE);
     $this->cacheBackend->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, ['entity_types', 'entity_bundles'])->will(function () {
         $this->get('entity_bundle_info:en')->willReturn((object) ['data' => 'cached data'])->shouldBeCalled();
     })->shouldBeCalled();
     $this->cacheTagsInvalidator->invalidateTags(['entity_bundles'])->shouldBeCalled();
     $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled();
     $expected = ['apple' => ['apple' => ['label' => 'Apple']], 'banana' => ['banana' => ['label' => 'Banana']]];
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame($expected, $bundle_info);
     $this->entityTypeBundleInfo->clearCachedBundles();
     $bundle_info = $this->entityTypeBundleInfo->getAllBundleInfo();
     $this->assertSame('cached data', $bundle_info);
 }
 /**
  * Assembles user-specific data used by Disqus SSO.
  *
  * @return array
  */
 protected function ssoUserData()
 {
     $account = $this->currentUser;
     $data = [];
     if (!$account->isAnonymous()) {
         $data['id'] = $account->id();
         $data['username'] = $account->getAccountName();
         $data['email'] = $account->getEmail();
         $data['url'] = Url::fromRoute('entity.user.canonical', ['user' => $account->id()], ['absolute' => TRUE])->toString();
         // Load the user's avatar.
         $user_picture_default = \Drupal::config('field.instance.user.user.user_picture')->get('settings.default_image');
         $user = user_load($account->id());
         if (isset($user->user_picture->target_id) && !empty($user->user_picture->target_id) && ($file = file_load($user->user_picture->target_id))) {
             $file_uri = $file->getFileUri();
             $data['avatar'] = !empty($file_uri) ? $file_uri : NULL;
         } elseif (!empty($user_picture_default['fid']) && ($file = file_load($user_picture_default['fid']))) {
             $file_uri = $file->getFileUri();
             $data['avatar'] = !empty($file_uri) ? $file_uri : NULL;
         }
         if (isset($data['avatar'])) {
             $data['avatar'] = file_create_url($data['avatar']);
         }
     }
     $this->moduleHandler->alter('disqus_user_data', $data);
     return $data;
 }
Esempio n. 15
0
  /**
   * {@inheritdoc}
   */
  public function entityForm($entity_form, FormStateInterface $form_state) {
    $operation = 'default';
    $controller = $this->entityTypeManager->getFormObject($entity_form['#entity']->getEntityTypeId(), $operation, FALSE);
    $controller->setEntity($entity_form['#entity']);
    $form_state->set(['inline_entity_form', $entity_form['#ief_id'], 'entity_form'], $controller);

    $child_form_state = $this->buildChildFormState($controller, $form_state, $entity_form['#entity'], $operation, $entity_form['#parents']);

    $entity_form = $controller->buildForm($entity_form, $child_form_state);

    if (!$entity_form['#display_actions']) {
      unset($entity_form['actions']);
    }

    // TODO - this is field-only part of the code. Figure out how to refactor.
    if ($child_form_state->get('inline_entity_form')) {
      foreach ($child_form_state->get('inline_entity_form') as $id => $data) {
        $form_state->set(['inline_entity_form', $id], $data);
      }
    }

    $form_state->set('field', $child_form_state->get('field'));

    $entity_form['#element_validate'][] = [get_class($this), 'entityFormValidate'];

    $entity_form['#ief_element_submit'][] = [get_class($this), 'entityFormSubmit'];
    $entity_form['#ief_element_submit'][] = [get_class($this), 'submitCleanFormState'];

    // Allow other modules to alter the form.
    $this->moduleHandler->alter('inline_entity_form_entity_form', $entity_form, $form_state);

    return $entity_form;
  }
Esempio n. 16
0
 /**
  * Gets all data invoked by hook_views_data().
  *
  * This is requested from the cache before being rebuilt.
  *
  * @return array
  *   An array of all data.
  */
 protected function getData()
 {
     $this->fullyLoaded = TRUE;
     if ($data = $this->cacheGet($this->baseCid)) {
         return $data->data;
     } else {
         $modules = $this->moduleHandler->getImplementations('views_data');
         $data = [];
         foreach ($modules as $module) {
             $views_data = $this->moduleHandler->invoke($module, 'views_data');
             // Set the provider key for each base table.
             foreach ($views_data as &$table) {
                 if (isset($table['table']) && !isset($table['table']['provider'])) {
                     $table['table']['provider'] = $module;
                 }
             }
             $data = NestedArray::mergeDeep($data, $views_data);
         }
         $this->moduleHandler->alter('views_data', $data);
         $this->processEntityTypes($data);
         // Keep a record with all data.
         $this->cacheSet($this->baseCid, $data);
         return $data;
     }
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function createAlias($module, $op, $source, $data, $type = NULL, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED)
 {
     $config = $this->configFactory->get('pathauto.settings');
     // Retrieve and apply the pattern for this content type.
     $pattern = $this->getPatternByEntity($module, $type, $langcode);
     // Allow other modules to alter the pattern.
     $context = array('module' => $module, 'op' => $op, 'source' => $source, 'data' => $data, 'type' => $type, 'language' => &$langcode);
     $this->moduleHandler->alter('pathauto_pattern', $pattern, $context);
     if (empty($pattern)) {
         // No pattern? Do nothing (otherwise we may blow away existing aliases...)
         return NULL;
     }
     // Special handling when updating an item which is already aliased.
     $existing_alias = NULL;
     if ($op == 'update' || $op == 'bulkupdate') {
         if ($existing_alias = $this->aliasStorageHelper->loadBySource($source, $langcode)) {
             switch ($config->get('update_action')) {
                 case PathautoManagerInterface::UPDATE_ACTION_NO_NEW:
                     // If an alias already exists,
                     // and the update action is set to do nothing,
                     // then gosh-darn it, do nothing.
                     return NULL;
             }
         }
     }
     // Replace any tokens in the pattern.
     // Uses callback option to clean replacements. No sanitization.
     $alias = $this->token->replace($pattern, $data, array('sanitize' => FALSE, 'clear' => TRUE, 'callback' => array($this, 'cleanTokenValues'), 'langcode' => $langcode, 'pathauto' => TRUE));
     // Check if the token replacement has not actually replaced any values. If
     // that is the case, then stop because we should not generate an alias.
     // @see token_scan()
     $pattern_tokens_removed = preg_replace('/\\[[^\\s\\]:]*:[^\\s\\]]*\\]/', '', $pattern);
     if ($alias === $pattern_tokens_removed) {
         return NULL;
     }
     $alias = $this->aliasCleaner->cleanAlias($alias);
     // Allow other modules to alter the alias.
     $context['source'] =& $source;
     $context['pattern'] = $pattern;
     $this->moduleHandler->alter('pathauto_alias', $alias, $context);
     // If we have arrived at an empty string, discontinue.
     if (!Unicode::strlen($alias)) {
         return NULL;
     }
     // If the alias already exists, generate a new, hopefully unique, variant.
     $original_alias = $alias;
     $this->aliasUniquifier->uniquify($alias, $source, $langcode);
     if ($original_alias != $alias) {
         // Alert the user why this happened.
         $this->messenger->addMessage($this->t('The automatically generated alias %original_alias conflicted with an existing alias. Alias changed to %alias.', array('%original_alias' => $original_alias, '%alias' => $alias)), $op);
     }
     // Return the generated alias if requested.
     if ($op == 'return') {
         return $alias;
     }
     // Build the new path alias array and send it off to be created.
     $path = array('source' => $source, 'alias' => $alias, 'language' => $langcode);
     return $this->aliasStorageHelper->save($path, $existing_alias, $op);
 }
Esempio n. 18
0
 /**
  * Builds the "contentsCss" configuration part of the CKEditor JS settings.
  *
  * @see getJSSettings()
  *
  * @param \Drupal\editor\Entity\Editor $editor
  *   A configured text editor object.
  * @return array
  *   An array containing the "contentsCss" configuration.
  */
 public function buildContentsCssJSSetting(EditorEntity $editor)
 {
     $css = array(drupal_get_path('module', 'ckeditor') . '/css/ckeditor-iframe.css', drupal_get_path('module', 'system') . '/css/system.module.css');
     $this->moduleHandler->alter('ckeditor_css', $css, $editor);
     $css = array_merge($css, _ckeditor_theme_css());
     $css = array_map('file_create_url', $css);
     return array_values($css);
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = $this->getBuilder()->build($this);
     $build['#title'] = $this->renderPageTitle($this->configuration['page_title']);
     // Allow other module to alter the built panel.
     $this->moduleHandler->alter('panels_build', $build, $this);
     return $build;
 }
 /**
  * Formats configuration schema as a form tree.
  *
  * @param \Drupal\Core\Config\Schema\Element $schema
  *   Schema definition of configuration.
  * @param array|string $config_data
  *   Configuration object of requested language, a string when done traversing
  *   the data building each sub-structure for the form.
  * @param array|string $base_config_data
  *   Configuration object of base language, a string when done traversing
  *   the data building each sub-structure for the form.
  * @param bool $open
  *   (optional) Whether or not the details element of the form should be open.
  *   Defaults to TRUE.
  * @param string|null $base_key
  *   (optional) Base configuration key. Defaults to an empty string.
  *
  * @return array
  *   An associative array containing the structure of the form.
  */
 protected function buildConfigForm(Element $schema, $config_data, $base_config_data, $open = TRUE, $base_key = '')
 {
     $build = array();
     foreach ($schema as $key => $element) {
         // Make the specific element key, "$base_key.$key".
         $element_key = implode('.', array_filter(array($base_key, $key)));
         $definition = $element->getDataDefinition();
         if (!$definition->getLabel()) {
             $definition->setLabel($this->t('N/A'));
         }
         if ($element instanceof Element) {
             // Build sub-structure and include it with a wrapper in the form
             // if there are any translatable elements there.
             $sub_build = $this->buildConfigForm($element, $config_data[$key], $base_config_data[$key], FALSE, $element_key);
             if (!empty($sub_build)) {
                 // For some configuration elements the same element structure can
                 // repeat multiple times, (like views displays, filters, etc.).
                 // So try to find a more usable title for the details summary. First
                 // check if there is an element which is called title or label, then
                 // check if there is an element which contains these words.
                 $title = '';
                 if (isset($sub_build['title']['source'])) {
                     $title = $sub_build['title']['source']['#markup'];
                 } elseif (isset($sub_build['label']['source'])) {
                     $title = $sub_build['label']['source']['#markup'];
                 } else {
                     foreach (array_keys($sub_build) as $title_key) {
                         if (isset($sub_build[$title_key]['source']) && (strpos($title_key, 'title') !== FALSE || strpos($title_key, 'label') !== FALSE)) {
                             $title = $sub_build[$title_key]['source']['#markup'];
                             break;
                         }
                     }
                 }
                 $build[$key] = array('#type' => 'details', '#title' => (!empty($title) ? strip_tags($title) . ' ' : '') . $this->t($definition['label']), '#open' => $open) + $sub_build;
             }
         } else {
             $definition = $element->getDataDefinition();
             // Invoke hook_config_translation_type_info_alter() implementations to
             // alter the configuration types.
             $definitions = array($definition['type'] => &$definition);
             $this->moduleHandler->alter('config_translation_type_info', $definitions);
             // Create form element only for translatable items.
             if (!isset($definition['translatable']) || !isset($definition['type'])) {
                 continue;
             }
             $value = $config_data[$key];
             $build[$element_key] = array('#theme' => 'config_translation_manage_form_element');
             $build[$element_key]['source'] = array('#markup' => $base_config_data[$key] ? '<span lang="' . $this->sourceLanguage->id . '">' . nl2br($base_config_data[$key] . '</span>') : t('(Empty)'), '#title' => $this->t('!label <span class="visually-hidden">(!source_language)</span>', array('!label' => $this->t($definition['label']), '!source_language' => $this->sourceLanguage->name)), '#type' => 'item');
             if (!isset($definition['form_element_class'])) {
                 $definition['form_element_class'] = '\\Drupal\\config_translation\\FormElement\\Textfield';
             }
             /** @var \Drupal\config_translation\FormElement\ElementInterface $form_element */
             $form_element = new $definition['form_element_class']();
             $build[$element_key]['translation'] = $form_element->getFormElement($definition, $this->language, $value);
         }
     }
     return $build;
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  *
  * For anonymous users, the "active" class will be calculated on the server,
  * because most sites serve each anonymous user the same cached page anyway.
  * For authenticated users, the "active" class will be calculated on the
  * client (through JavaScript), only data- attributes are added to links to
  * prevent breaking the render cache. The JavaScript is added in
  * system_page_attachments().
  *
  * @see system_page_attachments()
  */
 public function generate($text, Url $url, $collect_cacheability_metadata = FALSE)
 {
     // Performance: avoid Url::toString() needing to retrieve the URL generator
     // service from the container.
     $url->setUrlGenerator($this->urlGenerator);
     // Start building a structured representation of our link to be altered later.
     $variables = array('text' => is_array($text) ? drupal_render($text) : $text, 'url' => $url, 'options' => $url->getOptions());
     // Merge in default options.
     $variables['options'] += array('attributes' => array(), 'query' => array(), 'language' => NULL, 'set_active_class' => FALSE, 'absolute' => FALSE);
     // Add a hreflang attribute if we know the language of this link's url and
     // hreflang has not already been set.
     if (!empty($variables['options']['language']) && !isset($variables['options']['attributes']['hreflang'])) {
         $variables['options']['attributes']['hreflang'] = $variables['options']['language']->getId();
     }
     // Set the "active" class if the 'set_active_class' option is not empty.
     if (!empty($variables['options']['set_active_class']) && !$url->isExternal()) {
         // Add a "data-drupal-link-query" attribute to let the
         // drupal.active-link library know the query in a standardized manner.
         if (!empty($variables['options']['query'])) {
             $query = $variables['options']['query'];
             ksort($query);
             $variables['options']['attributes']['data-drupal-link-query'] = Json::encode($query);
         }
         // Add a "data-drupal-link-system-path" attribute to let the
         // drupal.active-link library know the path in a standardized manner.
         if ($url->isRouted() && !isset($variables['options']['attributes']['data-drupal-link-system-path'])) {
             // @todo System path is deprecated - use the route name and parameters.
             $system_path = $url->getInternalPath();
             // Special case for the front page.
             $variables['options']['attributes']['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path;
         }
     }
     // Remove all HTML and PHP tags from a tooltip, calling expensive strip_tags()
     // only when a quick strpos() gives suspicion tags are present.
     if (isset($variables['options']['attributes']['title']) && strpos($variables['options']['attributes']['title'], '<') !== FALSE) {
         $variables['options']['attributes']['title'] = strip_tags($variables['options']['attributes']['title']);
     }
     // Allow other modules to modify the structure of the link.
     $this->moduleHandler->alter('link', $variables);
     // Move attributes out of options since generateFromRoute() doesn't need
     // them. Include a placeholder for the href.
     $attributes = array('href' => '') + $variables['options']['attributes'];
     unset($variables['options']['attributes']);
     $url->setOptions($variables['options']);
     if (!$collect_cacheability_metadata) {
         $url_string = $url->toString($collect_cacheability_metadata);
     } else {
         $generated_url = $url->toString($collect_cacheability_metadata);
         $url_string = $generated_url->getGeneratedUrl();
         $generated_link = GeneratedLink::createFromObject($generated_url);
     }
     // The result of the URL generator is a plain-text URL to use as the href
     // attribute, and it is escaped by \Drupal\Core\Template\Attribute.
     $attributes['href'] = $url_string;
     $result = SafeMarkup::format('<a@attributes>@text</a>', array('@attributes' => new Attribute($attributes), '@text' => $variables['text']));
     return $collect_cacheability_metadata ? $generated_link->setGeneratedLink($result) : $result;
 }
Esempio n. 22
0
 /**
  * {@inheritdoc}
  */
 public function getTypeUri($entity_type, $bundle, $context = array())
 {
     // Per the interface documention of this method, the returned URI may
     // optionally also serve as the URL of a documentation page about this
     // bundle. However, the REST module does not currently implement such
     // a documentation page. Therefore, we return a URI assembled relative to
     // the site's base URL, which is sufficient to uniquely identify the site's
     // entity type and bundle for use in hypermedia formats, but we do not
     // take into account unclean URLs, language prefixing, or anything else
     // that would be required for Drupal to be able to respond with content
     // at this URL. If a module is installed that adds such content, but
     // requires this URL to be different (e.g., include a language prefix),
     // then the module must also override the TypeLinkManager class/service to
     // return the desired URL.
     $uri = $this->getLinkDomain() . "/rest/type/{$entity_type}/{$bundle}";
     $this->moduleHandler->alter('rest_type_uri', $uri, $context);
     return $uri;
 }
 /**
  * Prepares the AJAX commands to attach assets.
  *
  * @param \Drupal\Core\Ajax\AjaxResponse $response
  *   The AJAX response to update.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object that the AJAX is responding to.
  *
  * @return array
  *   An array of commands ready to be returned as JSON.
  */
 protected function buildAttachmentsCommands(AjaxResponse $response, Request $request)
 {
     $ajax_page_state = $request->request->get('ajax_page_state');
     // Aggregate CSS/JS if necessary, but only during normal site operation.
     $optimize_css = !defined('MAINTENANCE_MODE') && $this->config->get('css.preprocess');
     $optimize_js = !defined('MAINTENANCE_MODE') && $this->config->get('js.preprocess');
     $attachments = $response->getAttachments();
     // Resolve the attached libraries into asset collections.
     $assets = new AttachedAssets();
     $assets->setLibraries(isset($attachments['library']) ? $attachments['library'] : [])->setAlreadyLoadedLibraries(isset($ajax_page_state['libraries']) ? explode(',', $ajax_page_state['libraries']) : [])->setSettings(isset($attachments['drupalSettings']) ? $attachments['drupalSettings'] : []);
     $css_assets = $this->assetResolver->getCssAssets($assets, $optimize_css);
     list($js_assets_header, $js_assets_footer) = $this->assetResolver->getJsAssets($assets, $optimize_js);
     // Render the HTML to load these files, and add AJAX commands to insert this
     // HTML in the page. Settings are handled separately, afterwards.
     $settings = [];
     if (isset($js_assets_header['drupalSettings'])) {
         $settings = $js_assets_header['drupalSettings']['data'];
         unset($js_assets_header['drupalSettings']);
     }
     if (isset($js_assets_footer['drupalSettings'])) {
         $settings = $js_assets_footer['drupalSettings']['data'];
         unset($js_assets_footer['drupalSettings']);
     }
     // Prepend commands to add the assets, preserving their relative order.
     $resource_commands = array();
     if ($css_assets) {
         $css_render_array = $this->cssCollectionRenderer->render($css_assets);
         $resource_commands[] = new AddCssCommand((string) $this->renderer->renderPlain($css_render_array));
     }
     if ($js_assets_header) {
         $js_header_render_array = $this->jsCollectionRenderer->render($js_assets_header);
         $resource_commands[] = new PrependCommand('head', (string) $this->renderer->renderPlain($js_header_render_array));
     }
     if ($js_assets_footer) {
         $js_footer_render_array = $this->jsCollectionRenderer->render($js_assets_footer);
         $resource_commands[] = new AppendCommand('body', (string) $this->renderer->renderPlain($js_footer_render_array));
     }
     foreach (array_reverse($resource_commands) as $resource_command) {
         $response->addCommand($resource_command, TRUE);
     }
     // Prepend a command to merge changes and additions to drupalSettings.
     if (!empty($settings)) {
         // During Ajax requests basic path-specific settings are excluded from
         // new drupalSettings values. The original page where this request comes
         // from already has the right values. An Ajax request would update them
         // with values for the Ajax request and incorrectly override the page's
         // values.
         // @see system_js_settings_alter()
         unset($settings['path']);
         $response->addCommand(new SettingsCommand($settings, TRUE), TRUE);
     }
     $commands = $response->getCommands();
     $this->moduleHandler->alter('ajax_render', $commands);
     return $commands;
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 public function entityForm(array $entity_form, FormStateInterface $form_state)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = $entity_form['#entity'];
     $form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']);
     $form_display->buildForm($entity, $entity_form, $form_state);
     $entity_form['#ief_element_submit'][] = [get_class($this), 'submitCleanFormState'];
     // Allow other modules to alter the form.
     $this->moduleHandler->alter('inline_entity_form_entity_form', $entity_form, $form_state);
     return $entity_form;
 }
Esempio n. 25
0
 /**
  * {@inheritdoc}.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->config('securelogin.settings')->set('base_url', $form_state->getValue('base_url'))->set('secure_forms', $form_state->getValue('secure_forms'))->set('all_forms', $form_state->getValue('all_forms'))->set('other_forms', $form_state->getValue('other_forms'))->set('form_user_login_form', $form_state->getValue('form_user_login_form'))->set('form_user_pass_reset', $form_state->getValue('form_user_pass_reset'))->set('form_user_form', $form_state->getValue('form_user_form'))->set('form_user_register_form', $form_state->getValue('form_user_register_form'))->set('form_user_pass', $form_state->getValue('form_user_pass'))->save();
     $forms = [];
     $this->moduleHandler->alter('securelogin', $forms);
     foreach ($forms as $id => $item) {
         $this->config('securelogin.settings')->set("form_{$id}", $form_state->getValue("form_{$id}"))->save();
     }
     drupal_flush_all_caches();
     parent::submitForm($form, $form_state);
 }
 /**
  * Parses a given library file and allows module to alter it.
  *
  * This method sets the parsed information onto the library property.
  *
  * @param string $extension
  *   The name of the extension that registered a library.
  * @param string $library_file
  *   The relative filename to the DRUPAL_ROOT of the wanted library file.
  *
  * @return array
  *   An array of parsed library data.
  *
  * @throws \Drupal\Core\Asset\Exception\InvalidLibraryFileException
  *   Thrown when a parser exception got thrown.
  */
 protected function parseLibraryInfo($extension, $library_file)
 {
     try {
         $libraries = Yaml::decode(file_get_contents(DRUPAL_ROOT . '/' . $library_file));
     } catch (InvalidDataTypeException $e) {
         // Rethrow a more helpful exception to provide context.
         throw new InvalidLibraryFileException(sprintf('Invalid library definition in %s: %s', $library_file, $e->getMessage()), 0, $e);
     }
     // Allow modules to alter the module's registered libraries.
     $this->moduleHandler->alter('library_info', $libraries, $extension);
     return $libraries;
 }
Esempio n. 27
0
 /**
  * Helper method: Passes a query to the alteration system again.
  *
  * This allows Entity Reference to add a tag to an existing query so it can
  * ask access control mechanisms to alter it again.
  */
 protected function reAlterQuery(AlterableInterface $query, $tag, $base_table)
 {
     // Save the old tags and metadata.
     // For some reason, those are public.
     $old_tags = $query->alterTags;
     $old_metadata = $query->alterMetaData;
     $query->alterTags = array($tag => TRUE);
     $query->alterMetaData['base_table'] = $base_table;
     $this->moduleHandler->alter(array('query', 'query_' . $tag), $query);
     // Restore the tags and metadata.
     $query->alterTags = $old_tags;
     $query->alterMetaData = $old_metadata;
 }
Esempio n. 28
0
 /**
  * Gets the menu links defined in YAML files.
  *
  * @return array
  *   An array of default menu links.
  */
 public function getLinks()
 {
     $discovery = $this->getDiscovery();
     foreach ($discovery->findAll() as $module => $menu_links) {
         foreach ($menu_links as $machine_name => $menu_link) {
             $all_links[$machine_name] = $menu_link;
             $all_links[$machine_name]['machine_name'] = $machine_name;
             $all_links[$machine_name]['module'] = $module;
         }
     }
     $this->moduleHandler->alter('menu_link_defaults', $all_links);
     foreach ($all_links as $machine_name => $menu_link) {
         // Set the machine_name to the menu links added dynamically.
         if (!isset($menu_link['machine_name'])) {
             $all_links[$machine_name]['machine_name'] = $machine_name;
         }
         // Change the key to match the DB column for now.
         $all_links[$machine_name]['link_title'] = $all_links[$machine_name]['title'];
         unset($all_links[$machine_name]['title']);
     }
     return $all_links;
 }
Esempio n. 29
0
 /**
  * {@inheritdoc}
  */
 public function attach(array &$page)
 {
     if ($this->settings->get('custom.activate')) {
         $js_settings = array('transition' => $this->settings->get('custom.transition_type'), 'speed' => $this->settings->get('custom.transition_speed'), 'opacity' => $this->settings->get('custom.opacity'), 'slideshow' => $this->settings->get('custom.slideshow.slideshow') ? TRUE : FALSE, 'slideshowAuto' => $this->settings->get('custom.slideshow.auto') ? TRUE : FALSE, 'slideshowSpeed' => $this->settings->get('custom.slideshow.speed'), 'slideshowStart' => $this->settings->get('custom.slideshow.text_start'), 'slideshowStop' => $this->settings->get('custom.slideshow.text_stop'), 'current' => $this->settings->get('custom.text_current'), 'previous' => $this->settings->get('custom.text_previous'), 'next' => $this->settings->get('custom.text_next'), 'close' => $this->settings->get('custom.text_close'), 'overlayClose' => $this->settings->get('custom.overlayclose') ? TRUE : FALSE, 'maxWidth' => $this->settings->get('custom.maxwidth'), 'maxHeight' => $this->settings->get('custom.maxheight'), 'initialWidth' => $this->settings->get('custom.initialwidth'), 'initialHeight' => $this->settings->get('custom.initialheight'), 'fixed' => $this->settings->get('custom.fixed') ? TRUE : FALSE, 'scrolling' => $this->settings->get('custom.scrolling') ? TRUE : FALSE, 'mobiledetect' => $this->settings->get('advanced.mobile_detect') ? TRUE : FALSE, 'mobiledevicewidth' => $this->settings->get('advanced.mobile_device_width'));
     } else {
         $js_settings = array('opacity' => '0.85', 'current' => t('{current} of {total}'), 'previous' => t('« Prev'), 'next' => t('Next »'), 'close' => t('Close'), 'maxWidth' => '98%', 'maxHeight' => '98%', 'fixed' => TRUE, 'mobiledetect' => $this->settings->get('advanced.mobile_detect') ? TRUE : FALSE, 'mobiledevicewidth' => $this->settings->get('advanced.mobile_device_width'));
     }
     $style = $this->settings->get('custom.style');
     // Give other modules the possibility to override Colorbox settings and style.
     $this->moduleHandler->alter('colorbox_settings', $js_settings, $style);
     // Add colorbox js settings.
     $page['#attached']['drupalSettings']['colorbox'] = $js_settings;
     // Add and initialise the Colorbox plugin.
     if ($this->settings->get('advanced.compression_type' == 'minified')) {
         $page['#attached']['library'][] = 'colorbox/colorbox';
     } else {
         $page['#attached']['library'][] = 'colorbox/colorbox-dev';
     }
     // Add JS and CSS based on selected style.
     if ($style != 'none') {
         $page['#attached']['library'][] = "colorbox/{$style}";
     }
 }
Esempio n. 30
0
 /**
  * #lazy_builder callback; builds a comment's links.
  *
  * @param string $comment_entity_id
  *   The comment entity ID.
  * @param string $view_mode
  *   The view mode in which the comment entity is being viewed.
  * @param string $langcode
  *   The language in which the comment entity is being viewed.
  * @param bool $is_in_preview
  *  Whether the comment is currently being previewed.
  *
  * @return array
  *   A renderable array representing the comment links.
  */
 public function renderLinks($comment_entity_id, $view_mode, $langcode, $is_in_preview)
 {
     $links = array('#theme' => 'links__comment', '#pre_render' => array('drupal_pre_render_links'), '#attributes' => array('class' => array('links', 'inline')));
     if (!$is_in_preview) {
         /** @var \Drupal\comment\CommentInterface $entity */
         $entity = $this->entityManager->getStorage('comment')->load($comment_entity_id);
         $commented_entity = $entity->getCommentedEntity();
         $links['comment'] = $this->buildLinks($entity, $commented_entity);
         // Allow other modules to alter the comment links.
         $hook_context = array('view_mode' => $view_mode, 'langcode' => $langcode, 'commented_entity' => $commented_entity);
         $this->moduleHandler->alter('comment_links', $links, $entity, $hook_context);
     }
     return $links;
 }