/**
  * @return array The Render Array
  */
 public function search()
 {
     $formSubmitted = $this->currentRequest->getCurrentRequest()->get('search-button');
     $queryString = $this->currentRequest->getCurrentRequest()->get('search-value');
     $currentPage = $this->currentRequest->getCurrentRequest()->get('search-page');
     if (!isset($currentPage) || empty($currentPage)) {
         $currentPage = 1;
     }
     if (!isset($formSubmitted) || empty($formSubmitted) || $formSubmitted != SearchResultsController::FORM_SUBMITTED_VALUE || !isset($queryString) || empty($queryString)) {
         return ['#type' => 'markup', '#markup' => $this->t("No Search was performed")];
     }
     $config = $this->config('google_site_search.settings');
     $key = $config->get('google_site_search_key');
     $index = $config->get('google_site_search_index');
     if (empty($key) || !isset($key) || empty($index) || !isset($index)) {
         return ['#type' => 'markup', '#markup' => $this->t("The google site search is not configured correctly")];
     }
     /* @var $gssService \Drupal\google_site_search\GoogleSiteSearchSearch */
     $gssService = \Drupal::service('google_site_search.search');
     $currentLanguage = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
     $results = $gssService->getSearchResults($currentLanguage, $queryString, $key, $index, $currentPage);
     // check for errors or no results
     if ($results instanceof TranslatableMarkup || !isset($results['items']) || count($results['items']) === 0) {
         return ['#theme' => 'google_no_search_results', '#title' => t('No Search Results'), '#content' => ['query' => $queryString]];
     }
     return ['#theme' => 'google_search_results', '#title' => t('Search Results'), '#content' => ['items' => $results['items'], 'total' => $results['queries']['request'][0]['totalResults'], 'count' => $results['queries']['request'][0]['count'], 'start' => ($currentPage - 1) * 10 + 1, 'nextPage' => isset($results['queries']['nextPage']) ? $currentPage + 1 : 0, 'prevPage' => isset($results['queries']['prevPage']) ? $currentPage - 1 : 0, 'query' => $queryString], '#cache' => ['contexts' => $this->getCacheContexts()]];
 }
 /**
  * Set values for addthis_config based on Sharing API documentation. See
  * http://support.addthis.com/customer/portal/articles/1337994-the-addthis_config-variable
  * for more details.
  *
  * @TODO Allow alter of 'addthis_configuration'.
  *
  * @todo Add static cache.
  *
  * @todo Make the adding of configuration dynamic.
  *   SRP is lost here.
  */
 public function getAddThisConfig()
 {
     $config = $this->config_factory->get('addthis.settings');
     $enabled_services = $this->getServiceNamesAsCommaSeparatedString($config->get('compact_menu.enabled_services.addthis_enabled_services')) . 'more';
     $excluded_services = $this->getServiceNamesAsCommaSeparatedString($config->get('excluded_services.addthis_excluded_services'));
     $configuration = ['services_compact' => $enabled_services, 'services_exclude' => $excluded_services, 'ui_508_compliant' => $config->get('compact_menu.additionals.addthis_508_compliant'), 'ui_click' => $config->get('compact_menu.menu_style.addthis_click_to_open_compact_menu_enabled'), 'ui_cobrand' => $config->get('compact_menu.menu_style.addthis_co_brand'), 'ui_delay' => $config->get('compact_menu.menu_style.addthis_ui_delay'), 'ui_header_background' => $config->get('compact_menu.menu_style.addthis_ui_header_background_color'), 'ui_header_color' => $config->get('compact_menu.menu_style.addthis_ui_header_color'), 'ui_open_windows' => $config->get('compact_menu.menu_style.addthis_open_windows_enabled'), 'ui_use_css' => $config->get('compact_menu.additionals.addthis_standard_css_enabled'), 'ui_use_addressbook' => $config->get('compact_menu.additionals.addthis_addressbook_enabled'), 'ui_language' => $this->language_manager->getCurrentLanguage()->getId(), 'pubid' => $config->get('analytics.addthis_profile_id'), 'data_track_clickback' => $config->get('analytics.addthis_clickback_tracking_enabled')];
     //Ensure that the Google Analytics module is enabled for tracking.
     if (\Drupal::moduleHandler()->moduleExists('google_analytics')) {
         if ($config->get('analytics.addthis_google_analytics_tracking_enabled')) {
             $configuration['data_ga_property'] = $this->config_factory->get('google_analytics.settings')->get('account');
             $configuration['data_ga_social'] = $config->get('analytics.addthis_google_analytics_social_tracking_enabled');
         }
     }
     return $configuration;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getJSSettings(EditorEntity $editor)
 {
     $settings = array();
     // Get the settings for all enabled plugins, even the internal ones.
     $enabled_plugins = array_keys($this->ckeditorPluginManager->getEnabledPluginFiles($editor, TRUE));
     foreach ($enabled_plugins as $plugin_id) {
         $plugin = $this->ckeditorPluginManager->createInstance($plugin_id);
         $settings += $plugin->getConfig($editor);
     }
     // Fall back on English if no matching language code was found.
     $display_langcode = 'en';
     // Map the interface language code to a CKEditor translation.
     $ckeditor_langcodes = $this->getLangcodes();
     $language_interface = $this->languageManager->getCurrentLanguage();
     if (isset($ckeditor_langcodes[$language_interface->id])) {
         $display_langcode = $ckeditor_langcodes[$language_interface->id];
     }
     // Next, set the most fundamental CKEditor settings.
     $external_plugin_files = $this->ckeditorPluginManager->getEnabledPluginFiles($editor);
     $settings += array('toolbar' => $this->buildToolbarJSSetting($editor), 'contentsCss' => $this->buildContentsCssJSSetting($editor), 'extraPlugins' => implode(',', array_keys($external_plugin_files)), 'language' => $display_langcode, 'stylesSet' => FALSE);
     // Finally, set Drupal-specific CKEditor settings.
     $settings += array('drupalExternalPlugins' => array_map('file_create_url', $external_plugin_files));
     // Parse all CKEditor plugin JavaScript files for translations.
     if ($this->moduleHandler->moduleExists('locale')) {
         locale_js_translate(array_values($external_plugin_files));
     }
     ksort($settings);
     return $settings;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, array &$form_state)
 {
     $block = $this->entity;
     $account = $this->currentUser();
     if ($this->operation == 'edit') {
         $form['#title'] = $this->t('Edit custom block %label', array('%label' => $block->label()));
     }
     // Override the default CSS class name, since the user-defined custom block
     // type name in 'TYPE-block-form' potentially clashes with third-party class
     // names.
     $form['#attributes']['class'][0] = drupal_html_class('block-' . $block->bundle() . '-form');
     if ($this->moduleHandler->moduleExists('language')) {
         $language_configuration = language_get_default_configuration('block_content', $block->bundle());
         // Set the correct default language.
         if ($block->isNew()) {
             $language_default = $this->languageManager->getCurrentLanguage($language_configuration['langcode']);
             $block->langcode->value = $language_default->id;
         }
     }
     $form['langcode'] = array('#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $block->getUntranslated()->language()->id, '#languages' => LanguageInterface::STATE_ALL, '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show']);
     $form['advanced'] = array('#type' => 'vertical_tabs', '#weight' => 99);
     // Add a log field if the "Create new revision" option is checked, or if the
     // current user has the ability to check that option.
     $form['revision_information'] = array('#type' => 'details', '#title' => $this->t('Revision information'), '#open' => $block->isNewRevision(), '#group' => 'advanced', '#attributes' => array('class' => array('block-content-form-revision-information')), '#attached' => array('library' => array('block_content/drupal.block_content')), '#weight' => 20, '#access' => $block->isNewRevision() || $account->hasPermission('administer blocks'));
     $form['revision_information']['revision'] = array('#type' => 'checkbox', '#title' => $this->t('Create new revision'), '#default_value' => $block->isNewRevision(), '#access' => $account->hasPermission('administer blocks'));
     // Check the revision log checkbox when the log textarea is filled in.
     // This must not happen if "Create new revision" is enabled by default,
     // since the state would auto-disable the checkbox otherwise.
     if (!$block->isNewRevision()) {
         $form['revision_information']['revision']['#states'] = array('checked' => array('textarea[name="revision_log"]' => array('empty' => FALSE)));
     }
     $form['revision_information']['revision_log'] = array('#type' => 'textarea', '#title' => $this->t('Revision log message'), '#rows' => 4, '#default_value' => $block->getRevisionLog(), '#description' => $this->t('Briefly describe the changes you have made.'));
     return parent::form($form, $form_state, $block);
 }
Example #5
0
 /**
  * Helper function to generate link.
  *
  * @param $nodeId
  *   Target node ID.
  * @param $label
  *   Target node label.
  *
  * @return array|\mixed[]
  *   Link render array.
  */
 public function flippy_generate_link($nodeId, $label)
 {
     $token_service = $this->token;
     $language = $this->languageManager->getCurrentLanguage()->getId();
     $url = Url::fromRoute('entity.node.canonical');
     $url->setRouteParameter('node', $nodeId);
     $flippyLink = Link::fromTextAndUrl($token_service->replace($label, ['node' => Node::load($nodeId)], ['langcode' => $language]), $url);
     return $flippyLink->toRenderable();
 }
 /**
  * Enhances a page object based on a render array.
  *
  * @param \Drupal\Core\Page\HtmlPage $page
  *   The page object to enhance.
  * @param array $page_array
  *   The page array to extract onto the page object.
  *
  * @return \Drupal\Core\Page\HtmlPage
  *   The modified page object.
  */
 public function preparePage(HtmlPage $page, &$page_array)
 {
     $page_array['#page'] = $page;
     // HTML element attributes.
     $language_interface = $this->languageManager->getCurrentLanguage();
     $html_attributes = $page->getHtmlAttributes();
     $html_attributes['lang'] = $language_interface->id;
     $html_attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr';
     $this->setDefaultMetaTags($page);
     // @todo: collect feed links from #attached rather than a static once
     // http://drupal.org/node/2256365 is completed.
     foreach (drupal_get_feeds() as $feed) {
         // Force the URL to be absolute, for consistency with other <link> tags
         // output by Drupal.
         $link = new FeedLinkElement($feed['title'], url($feed['url'], array('absolute' => TRUE)));
         $page->addLinkElement($link);
     }
     return $page;
 }
 /**
  * Sets extra headers on successful responses.
  *
  * @param Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The event to process.
  */
 public function onRespond(FilterResponseEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $request = $event->getRequest();
     $response = $event->getResponse();
     // Set the X-UA-Compatible HTTP header to force IE to use the most recent
     // rendering engine or use Chrome's frame rendering engine if available.
     $response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', FALSE);
     // Set the Content-language header.
     $response->headers->set('Content-language', $this->languageManager->getCurrentLanguage()->id);
     // Attach globally-declared headers to the response object so that Symfony
     // can send them for us correctly.
     // @todo remove this once we have removed all drupal_add_http_header()
     //   calls.
     $headers = drupal_get_http_header();
     foreach ($headers as $name => $value) {
         $response->headers->set($name, $value, FALSE);
     }
     $is_cacheable = drupal_page_is_cacheable();
     // Add headers necessary to specify whether the response should be cached by
     // proxies and/or the browser.
     if ($is_cacheable && $this->config->get('cache.page.max_age') > 0) {
         if (!$this->isCacheControlCustomized($response)) {
             $this->setResponseCacheable($response, $request);
         }
     } else {
         $this->setResponseNotCacheable($response, $request);
     }
     // Currently it is not possible to cache some types of responses. Therefore
     // exclude binary file responses (generated files, e.g. images with image
     // styles) and streamed responses (files directly read from the disk).
     // see: https://github.com/symfony/symfony/issues/9128#issuecomment-25088678
     if ($is_cacheable && $this->config->get('cache.page.use_internal') && !$response instanceof BinaryFileResponse && !$response instanceof StreamedResponse) {
         // Store the response in the internal page cache.
         drupal_page_set_cache($response, $request);
         $response->headers->set('X-Drupal-Cache', 'MISS');
         drupal_serve_page_from_cache($response, $request);
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function getAliasByPath($path, $langcode = NULL)
 {
     // If no language is explicitly specified we default to the current URL
     // language. If we used a language different from the one conveyed by the
     // requested URL, we might end up being unable to check if there is a path
     // alias matching the URL path.
     $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->id;
     // Check the path whitelist, if the top-level part before the first /
     // is not in the list, then there is no need to do anything further,
     // it is not in the database.
     if (empty($path) || !$this->whitelist->get(strtok($path, '/'))) {
         return $path;
     }
     // During the first call to this method per language, load the expected
     // paths for the page from cache.
     if (empty($this->langcodePreloaded[$langcode])) {
         $this->langcodePreloaded[$langcode] = TRUE;
         $this->lookupMap[$langcode] = array();
         // Load the cached paths that should be used for preloading. This only
         // happens if a cache key has been set.
         if ($this->preloadedPathLookups === FALSE) {
             $this->preloadedPathLookups = array();
             if ($this->cacheKey && ($cached = $this->cache->get($this->cacheKey))) {
                 $this->preloadedPathLookups = $cached->data;
             }
         }
         // Load paths from cache.
         if (!empty($this->preloadedPathLookups[$langcode])) {
             $this->lookupMap[$langcode] = $this->storage->preloadPathAlias($this->preloadedPathLookups[$langcode], $langcode);
             // Keep a record of paths with no alias to avoid querying twice.
             $this->noAlias[$langcode] = array_flip(array_diff_key($this->preloadedPathLookups[$langcode], array_keys($this->lookupMap[$langcode])));
         }
     }
     // If we already know that there are no aliases for this path simply return.
     if (!empty($this->noAlias[$langcode][$path])) {
         return $path;
     }
     // If the alias has already been loaded, return it from static cache.
     if (isset($this->lookupMap[$langcode][$path])) {
         return $this->lookupMap[$langcode][$path];
     }
     // Try to load alias from storage.
     if ($alias = $this->storage->lookupPathAlias($path, $langcode)) {
         $this->lookupMap[$langcode][$path] = $alias;
         $this->cacheNeedsWriting = TRUE;
         return $alias;
     }
     // We can't record anything into $this->lookupMap because we didn't find any
     // aliases for this path. Thus cache to $this->noAlias.
     $this->noAlias[$langcode][$path] = TRUE;
     $this->cacheNeedsWriting = TRUE;
     return $path;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $langcode = $this->languageManager->getCurrentLanguage()->id;
     $account = $form_state['values']['account'];
     // Mail one time login URL and instructions using current language.
     $mail = _user_mail_notify('password_reset', $account, $langcode);
     if (!empty($mail)) {
         $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', array('%name' => $account->getUsername(), '%email' => $account->getEmail()));
         drupal_set_message($this->t('Further instructions have been sent to your email address.'));
     }
     $form_state->setRedirect('user.page');
 }
 /**
  * @covers ::resolveCurrencyLocale
  */
 function testResolveCurrencyLocaleWithSiteDefaultCountry()
 {
     $this->prepareLanguageManager();
     $site_default_country = 'IN';
     $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $config->expects($this->any())->method('get')->with('country.default')->willReturn($site_default_country);
     $this->configFactory->expects($this->once())->method('get')->with('system.data')->willReturn($config);
     $currency_locale = $this->getMock(CurrencyLocaleInterface::class);
     $this->currencyLocaleStorage->expects($this->any())->method('load')->with($this->languageManager->getCurrentLanguage(Language::TYPE_CONTENT)->getId() . '_' . $site_default_country)->willReturn($currency_locale);
     // Test loading the fallback locale.
     $this->assertSame($currency_locale, $this->sut->resolveCurrencyLocale());
 }
Example #11
0
 /**
  * Lists locale translation filters that can be applied.
  */
 protected function translateFilters()
 {
     $filters = array();
     // Get all languages, except English.
     $this->languageManager->reset();
     $languages = language_list();
     $language_options = array();
     foreach ($languages as $langcode => $language) {
         if ($langcode != 'en' || locale_translate_english()) {
             $language_options[$langcode] = $language->name;
         }
     }
     // Pick the current interface language code for the filter.
     $default_langcode = $this->languageManager->getCurrentLanguage()->id;
     if (!isset($language_options[$default_langcode])) {
         $available_langcodes = array_keys($language_options);
         $default_langcode = array_shift($available_langcodes);
     }
     $filters['string'] = array('title' => $this->t('String contains'), 'description' => $this->t('Leave blank to show all strings. The search is case sensitive.'), 'default' => '');
     $filters['langcode'] = array('title' => $this->t('Translation language'), 'options' => $language_options, 'default' => $default_langcode);
     $filters['translation'] = array('title' => $this->t('Search in'), 'options' => array('all' => $this->t('Both translated and untranslated strings'), 'translated' => $this->t('Only translated strings'), 'untranslated' => $this->t('Only untranslated strings')), 'default' => 'all');
     $filters['customized'] = array('title' => $this->t('Translation type'), 'options' => array('all' => $this->t('All'), LOCALE_NOT_CUSTOMIZED => $this->t('Non-customized translation'), LOCALE_CUSTOMIZED => $this->t('Customized translation')), 'states' => array('visible' => array(':input[name=translation]' => array('value' => 'translated'))), 'default' => 'all');
     return $filters;
 }
Example #12
0
 /**
  * Return the language code of the language the field should be displayed in,
  * according to the settings.
  */
 function field_langcode(EntityInterface $entity)
 {
     if ($this->getFieldDefinition()->isTranslatable()) {
         $default_langcode = language_default()->id;
         $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), array($this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id, $default_langcode), $this->view->display_handler->options['field_langcode']);
         // Give the Entity Field API a chance to fallback to a different language
         // (or LanguageInterface::LANGCODE_NOT_SPECIFIED), in case the field has
         // no data for the selected language. FieldItemListInterface::view() does
         // this as well, but since the returned language code is used before
         // calling it, the fallback needs to happen explicitly.
         $langcode = $this->entityManager->getTranslationFromContext($entity, $langcode)->language()->id;
         return $langcode;
     } else {
         return LanguageInterface::LANGCODE_NOT_SPECIFIED;
     }
 }
Example #13
0
 /**
  * Constructs a \Drupal\Core\Menu\LocalTaskManager object.
  *
  * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
  *   An object to use in introspecting route methods.
  * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  *   The request object to use for building titles and paths for plugin instances.
  * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
  *   The route provider to load routes by name.
  * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
  *   The route builder.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler.
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache
  *   The cache backend.
  * @param \Drupal\Core\Language\LanguageManager $language_manager
  *   The language manager.
  * @param \Drupal\Core\Access\AccessManagerInterface $access_manager
  *   The access manager.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The current user.
  */
 public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, AccessManagerInterface $access_manager, AccountInterface $account)
 {
     $this->discovery = new YamlDiscovery('links.task', $module_handler->getModuleDirectories());
     $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
     $this->factory = new ContainerFactory($this);
     $this->controllerResolver = $controller_resolver;
     $this->requestStack = $request_stack;
     $this->routeProvider = $route_provider;
     $this->routeBuilder = $route_builder;
     $this->accessManager = $access_manager;
     $this->account = $account;
     $this->moduleHandler = $module_handler;
     $this->alterInfo('local_tasks');
     $this->setCacheBackend($cache, 'local_task_plugins:' . $language_manager->getCurrentLanguage()->getId(), array('local_task' => TRUE));
 }