コード例 #1
0
ファイル: RedirectChecker.php プロジェクト: isramv/camp-gdl
 /**
  * Determines if redirect may be performed.
  *
  * @param Request $request
  *   The current request object.
  * @param string $route_name
  *   The current route name.
  *
  * @return bool
  *   TRUE if redirect may be performed.
  */
 public function canRedirect(Request $request, $route_name = NULL)
 {
     $can_redirect = TRUE;
     if (isset($route_name)) {
         $route = $this->routeProvider->getRouteByName($route_name);
         if ($this->config->get('access_check')) {
             // Do not redirect if is a protected page.
             $can_redirect &= $this->accessManager->check($route, $request, $this->account);
         }
     } else {
         $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
     }
     if (strpos($request->getScriptName(), 'index.php') === FALSE) {
         // Do not redirect if the root script is not /index.php.
         $can_redirect = FALSE;
     } elseif (!($request->isMethod('GET') || $request->isMethod('HEAD'))) {
         // Do not redirect if this is other than GET request.
         $can_redirect = FALSE;
     } elseif ($this->state->get('system.maintenance_mode') || defined('MAINTENANCE_MODE')) {
         // Do not redirect in offline or maintenance mode.
         $can_redirect = FALSE;
     } elseif ($this->config->get('ignore_admin_path') && isset($route)) {
         // Do not redirect on admin paths.
         $can_redirect &= !(bool) $route->getOption('_admin_route');
     }
     return $can_redirect;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>');
     $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary'));
     $breadcrumb[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
     return $breadcrumb;
 }
コード例 #3
0
 /**
  * Create an example node, test block through admin and user interfaces.
  */
 public function testCronExampleBasic()
 {
     // Pretend that cron has never been run (even though simpletest seems to
     // run it once...)
     $this->cronConfig->set('cron_example_next_execution', 0);
     $this->drupalGet('examples/cron_example');
     // Initial run should cause cron_example_cron() to fire.
     $post = [];
     $this->drupalPostForm('examples/cron_example', $post, t('Run cron now'));
     $this->assertText(t('cron_example executed at'));
     // Forcing should also cause cron_example_cron() to fire.
     $post['cron_reset'] = TRUE;
     $this->drupalPostForm(NULL, $post, t('Run cron now'));
     $this->assertText(t('cron_example executed at'));
     // But if followed immediately and not forced, it should not fire.
     $post['cron_reset'] = FALSE;
     $this->drupalPostForm(NULL, $post, t('Run cron now'));
     $this->assertNoText(t('cron_example executed at'));
     $this->assertText(t('There are currently 0 items in queue 1 and 0 items in queue 2'));
     $post = ['num_items' => 5, 'queue' => 'cron_example_queue_1'];
     $this->drupalPostForm(NULL, $post, t('Add jobs to queue'));
     $this->assertText('There are currently 5 items in queue 1 and 0 items in queue 2');
     $post = ['num_items' => 100, 'queue' => 'cron_example_queue_2'];
     $this->drupalPostForm(NULL, $post, t('Add jobs to queue'));
     $this->assertText('There are currently 5 items in queue 1 and 100 items in queue 2');
     $post = [];
     $this->drupalPostForm('examples/cron_example', $post, t('Run cron now'));
     $this->assertPattern('/Queue 1 worker processed item with sequence 5 /');
     $this->assertPattern('/Queue 2 worker processed item with sequence 100 /');
 }
コード例 #4
0
ファイル: ConfigEventsTest.php プロジェクト: ddrozdik/dmaps
 /**
  * Tests configuration events.
  */
 function testConfigEvents()
 {
     $name = 'config_events_test.test';
     $config = new Config($name, \Drupal::service('config.storage'), \Drupal::service('event_dispatcher'), \Drupal::service('config.typed'));
     $config->set('key', 'initial');
     \Drupal::state()->get('config_events_test.event', FALSE);
     $this->assertIdentical(\Drupal::state()->get('config_events_test.event', array()), array(), 'No events fired by creating a new configuration object');
     $config->save();
     $event = \Drupal::state()->get('config_events_test.event', array());
     $this->assertIdentical($event['event_name'], ConfigEvents::SAVE);
     $this->assertIdentical($event['current_config_data'], array('key' => 'initial'));
     $this->assertIdentical($event['raw_config_data'], array('key' => 'initial'));
     $this->assertIdentical($event['original_config_data'], array());
     $config->set('key', 'updated')->save();
     $event = \Drupal::state()->get('config_events_test.event', array());
     $this->assertIdentical($event['event_name'], ConfigEvents::SAVE);
     $this->assertIdentical($event['current_config_data'], array('key' => 'updated'));
     $this->assertIdentical($event['raw_config_data'], array('key' => 'updated'));
     $this->assertIdentical($event['original_config_data'], array('key' => 'initial'));
     $config->delete();
     $event = \Drupal::state()->get('config_events_test.event', array());
     $this->assertIdentical($event['event_name'], ConfigEvents::DELETE);
     $this->assertIdentical($event['current_config_data'], array());
     $this->assertIdentical($event['raw_config_data'], array());
     $this->assertIdentical($event['original_config_data'], array('key' => 'updated'));
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     if ($this->sharethisSettings->get('location') === 'block') {
         $st_js = $this->sharethisManager->sharethisIncludeJs();
         $markup = $this->sharethisManager->blockContents();
         return ['#theme' => 'sharethis_block', '#content' => $markup, '#attached' => array('library' => array('sharethis/sharethispickerexternalbuttonsws', 'sharethis/sharethispickerexternalbuttons', 'sharethis/sharethis'), 'drupalSettings' => array('sharethis' => $st_js))];
     }
 }
コード例 #6
0
ファイル: ItemsImporter.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function refresh(FeedInterface $feed)
 {
     // Store feed URL to track changes.
     $feed_url = $feed->getUrl();
     // Fetch the feed.
     try {
         $success = $this->fetcherManager->createInstance($this->config->get('fetcher'))->fetch($feed);
     } catch (PluginException $e) {
         $success = FALSE;
         watchdog_exception('aggregator', $e);
     }
     // Store instances in an array so we dont have to instantiate new objects.
     $processor_instances = array();
     foreach ($this->config->get('processors') as $processor) {
         try {
             $processor_instances[$processor] = $this->processorManager->createInstance($processor);
         } catch (PluginException $e) {
             watchdog_exception('aggregator', $e);
         }
     }
     // We store the hash of feed data in the database. When refreshing a
     // feed we compare stored hash and new hash calculated from downloaded
     // data. If both are equal we say that feed is not updated.
     $hash = hash('sha256', $feed->source_string);
     $has_new_content = $success && $feed->getHash() != $hash;
     if ($has_new_content) {
         // Parse the feed.
         try {
             if ($this->parserManager->createInstance($this->config->get('parser'))->parse($feed)) {
                 if (!$feed->getWebsiteUrl()) {
                     $feed->setWebsiteUrl($feed->getUrl());
                 }
                 $feed->setHash($hash);
                 // Update feed with parsed data.
                 $feed->save();
                 // Log if feed URL has changed.
                 if ($feed->getUrl() != $feed_url) {
                     $this->logger->notice('Updated URL for feed %title to %url.', array('%title' => $feed->label(), '%url' => $feed->getUrl()));
                 }
                 $this->logger->notice('There is new syndicated content from %site.', array('%site' => $feed->label()));
                 // If there are items on the feed, let enabled processors process them.
                 if (!empty($feed->items)) {
                     foreach ($processor_instances as $instance) {
                         $instance->process($feed);
                     }
                 }
             }
         } catch (PluginException $e) {
             watchdog_exception('aggregator', $e);
         }
     }
     // Processing is done, call postProcess on enabled processors.
     foreach ($processor_instances as $instance) {
         $instance->postProcess($feed);
     }
     return $has_new_content;
 }
コード例 #7
0
ファイル: ConfigFactoryTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * @covers ::rename
  */
 public function testRename()
 {
     $old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
     $new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
     $this->storage->expects($this->exactly(2))->method('readMultiple')->willReturnMap([[[$old->getName()], $old->getRawData()], [[$new->getName()], $new->getRawData()]]);
     $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with($old->getCacheTags());
     $this->storage->expects($this->once())->method('rename')->with($old->getName(), $new->getName());
     $this->configFactory->rename($old->getName(), $new->getName());
 }
コード例 #8
0
 /**
  * Constructs a ImageEffectsPluginBase object.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
  *   The configuration factory.
  * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
  *   The URL generator.
  * @param \Psr\Log\LoggerInterface $logger
  *   The image_effects logger.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, UrlGeneratorInterface $url_generator, LoggerInterface $logger)
 {
     $this->config = $config_factory->getEditable('image_effects.settings');
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->pluginType = $configuration['plugin_type'];
     $config = $this->config->get($this->pluginType . '.plugin_settings.' . $plugin_id);
     $this->setConfiguration(array_merge($this->defaultConfiguration(), is_array($config) ? $config : array()));
     $this->urlGenerator = $url_generator;
     $this->logger = $logger;
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addCacheContexts(['route']);
     $links[] = Link::createFromRoute($this->t('Home'), '<front>');
     $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary'));
     $breadcrumb->addCacheableDependency($vocabulary);
     $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
     return $breadcrumb->setLinks($links);
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function importDelete($name, Config $new_config, Config $old_config)
 {
     // If the field has been deleted in the same import, the instance will be
     // deleted by then, and there is nothing left to do. Just return TRUE so
     // that the file does not get written to active store.
     if (!$old_config->get()) {
         return TRUE;
     }
     return parent::importDelete($name, $new_config, $old_config);
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     foreach ($row->getRawDestination() as $key => $value) {
         if (isset($value) || !empty($this->configuration['store null'])) {
             $this->config->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $key), $value);
         }
     }
     $this->config->save();
     return TRUE;
 }
コード例 #12
0
ファイル: AutomatedCron.php プロジェクト: aWEBoLabs/taxi
 /**
  * Run the automated cron if enabled.
  *
  * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event
  *   The Event to process.
  */
 public function onTerminate(PostResponseEvent $event)
 {
     $interval = $this->config->get('interval');
     if ($interval > 0) {
         $cron_next = $this->state->get('system.cron_last', 0) + $interval;
         if ((int) $event->getRequest()->server->get('REQUEST_TIME') > $cron_next) {
             $this->cron->run();
         }
     }
 }
コード例 #13
0
ファイル: SysLog.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = array())
 {
     global $base_url;
     // Ensure we have a connection available.
     $this->openConnection();
     // Populate the message placeholders and then replace them in the message.
     $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
     $message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
     $entry = strtr($this->config->get('format'), array('!base_url' => $base_url, '!timestamp' => $context['timestamp'], '!type' => $context['channel'], '!ip' => $context['ip'], '!request_uri' => $context['request_uri'], '!referer' => $context['referer'], '!uid' => $context['uid'], '!link' => strip_tags($context['link']), '!message' => strip_tags($message)));
     syslog($level, $entry);
 }
コード例 #14
0
 public function getPlugin($plugin_id = NULL)
 {
     $plugin_id = $plugin_id ?: $this->config->get($this->getType() . '.plugin_id');
     $plugins = $this->getAvailablePlugins();
     // Check if plugin is available.
     if (!isset($plugins[$plugin_id]) || !class_exists($plugins[$plugin_id]['class'])) {
         trigger_error("image_effects " . $this->getType() . " handling plugin '{$plugin_id}' is no longer available.", E_USER_ERROR);
         $plugin_id = NULL;
     }
     return $this->createInstance($plugin_id, array('plugin_type' => $this->getType()));
 }
コード例 #15
0
 /**
  * Filters data in the override based on what is currently in configuration.
  *
  * @param \Drupal\Core\Config\Config $config
  *   Current configuration object.
  * @param \Drupal\Core\Config\StorableConfigBase $override
  *   Override object corresponding to the configuration to filter data in.
  */
 protected function filterOverride(Config $config, StorableConfigBase $override)
 {
     $override_data = $override->get();
     $this->filterNestedArray($config->get(), $override_data);
     if (empty($override_data)) {
         // If no override values are left that would apply, remove the override.
         $override->delete();
     } else {
         // Otherwise set the filtered override values back.
         $override->setData($override_data)->save();
     }
 }
コード例 #16
0
 /**
  * Checks access to the route.
  *
  * @param string $route_name
  *   The current route name.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return bool
  *   TRUE if access is granted.
  */
 public function canRedirect($route_name, Request $request)
 {
     $do_redirect = TRUE;
     /** @var \Symfony\Component\Routing\Route $route */
     $route = $this->routeProvider->getRouteByName($route_name);
     if ($this->config->get('access_check')) {
         $do_redirect &= $this->accessManager->check($route, $request, $this->account);
     }
     if ($this->config->get('ignore_admin_path')) {
         $do_redirect &= !(bool) $route->getOption('_admin_route');
     }
     return $do_redirect;
 }
コード例 #17
0
ファイル: AutomaticCron.php プロジェクト: nsp15/Drupal8
 /**
  * Run the automated cron if enabled.
  *
  * @param Symfony\Component\HttpKernel\Event\PostResponseEvent $event
  *   The Event to process.
  */
 public function onTerminate(PostResponseEvent $event)
 {
     // If the site is not fully installed, suppress the automated cron run.
     // Otherwise it could be triggered prematurely by Ajax requests during
     // installation.
     if ($this->state->get('install_task') == 'done') {
         $threshold = $this->config->get('threshold.autorun');
         if ($threshold > 0) {
             $cron_next = $this->state->get('system.cron_last', 0) + $threshold;
             if (REQUEST_TIME > $cron_next) {
                 $this->cron->run();
             }
         }
     }
 }
コード例 #18
0
ファイル: DisqusComment.php プロジェクト: hugronaphor/cornel
 /**
  * {@inheritdoc}
  */
 public function initializeIterator()
 {
     if ($disqus = disqus_api()) {
         try {
             $posts = $disqus->forums->listPosts(array('forum' => $this->config->get('disqus_domain')));
         } catch (\Exception $exception) {
             drupal_set_message(t('There was an error loading the forum details. Please check you API keys and try again.', 'error'));
             $this->logger->error('Error loading the Disqus PHP API. Check your forum name.', array());
             return FALSE;
         }
         $items = array();
         foreach ($posts as $post) {
             $id = $post['id'];
             $items[$id]['id'] = $id;
             $items[$id]['pid'] = $post['parent'];
             $thread = $disqus->threads->details(array('thread' => $post['thread']));
             $items[$id]['identifier'] = $thread['identifier'];
             $items[$id]['name'] = $post['author']['name'];
             $items[$id]['email'] = $post['author']['email'];
             $items[$id]['user_id'] = $post['author']['id'];
             $items[$id]['url'] = $post['author']['url'];
             $items[$id]['ipAddress'] = $post['ipAddress'];
             $items[$id]['isAnonymous'] = $post['author']['isAnonymous'];
             $items[$id]['createdAt'] = $post['createdAt'];
             $items[$id]['comment'] = $post['message'];
             $items[$id]['isEdited'] = $post['isEdited'];
         }
     }
     return new \ArrayIterator($items);
 }
コード例 #19
0
 /**
  * {@inheritdoc}
  */
 public function forbiddenMessage(EntityInterface $entity, $field_name)
 {
     if (!isset($this->authenticatedCanPostComments)) {
         // We only output a link if we are certain that users will get the
         // permission to post comments by logging in.
         $this->authenticatedCanPostComments = $this->entityManager->getStorage('user_role')->load(DRUPAL_AUTHENTICATED_RID)->hasPermission('post comments');
     }
     if ($this->authenticatedCanPostComments) {
         // We cannot use drupal_get_destination() because these links
         // sometimes appear on /node and taxonomy listing pages.
         if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) {
             $destination = array('destination' => 'comment/reply/' . $entity->getEntityTypeId() . '/' . $entity->id() . '/' . $field_name . '#comment-form');
         } else {
             $destination = array('destination' => $entity->getSystemPath() . '#comment-form');
         }
         if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
             // Users can register themselves.
             return $this->t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)), '@register' => $this->urlGenerator->generateFromRoute('user.register', array(), array('query' => $destination))));
         } else {
             // Only admins can add new users, no public registration.
             return $this->t('<a href="@login">Log in</a> to post comments', array('@login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination))));
         }
     }
     return '';
 }
コード例 #20
0
ファイル: ControllerBase.php プロジェクト: ddrozdik/dmaps
 /**
  * Retrieves a configuration object.
  *
  * This is the main entry point to the configuration API. Calling
  * @code $this->config('book.admin') @endcode will return a configuration
  * object in which the book module can store its administrative settings.
  *
  * @param string $name
  *   The name of the configuration object to retrieve. The name corresponds to
  *   a configuration file. For @code \Drupal::config('book.admin') @endcode,
  *   the config object returned will contain the contents of book.admin
  *   configuration file.
  *
  * @return \Drupal\Core\Config\Config
  *   A configuration object.
  */
 protected function config($name)
 {
     if (!$this->configFactory) {
         $this->configFactory = $this->container()->get('config.factory');
     }
     return $this->configFactory->get($name);
 }
コード例 #21
0
 /**
  * Processes asset libraries into render arrays.
  *
  * @param array $attached
  *   The attachments to process.
  * @param array $placeholders
  *   The placeholders that exist in the response.
  *
  * @return array
  *   An array keyed by asset type, with keys:
  *     - styles
  *     - scripts
  *     - scripts_bottom
  */
 protected function processAssetLibraries(array $attached, array $placeholders)
 {
     $all_attached = ['#attached' => $attached];
     $assets = AttachedAssets::createFromRenderArray($all_attached);
     // Take Ajax page state into account, to allow for something like Turbolinks
     // to be implemented without altering core.
     // @see https://github.com/rails/turbolinks/
     // @todo https://www.drupal.org/node/2497115 - Below line is broken due to ->request.
     $ajax_page_state = $this->requestStack->getCurrentRequest()->request->get('ajax_page_state');
     $assets->setAlreadyLoadedLibraries(isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : []);
     $variables = [];
     // Print styles - if present.
     if (isset($placeholders['styles'])) {
         // Optimize CSS if necessary, but only during normal site operation.
         $optimize_css = !defined('MAINTENANCE_MODE') && $this->config->get('css.preprocess');
         $variables['styles'] = $this->cssCollectionRenderer->render($this->assetResolver->getCssAssets($assets, $optimize_css));
     }
     // Print scripts - if any are present.
     if (isset($placeholders['scripts']) || isset($placeholders['scripts_bottom'])) {
         // Optimize JS if necessary, but only during normal site operation.
         $optimize_js = !defined('MAINTENANCE_MODE') && !\Drupal::state()->get('system.maintenance_mode') && $this->config->get('js.preprocess');
         list($js_assets_header, $js_assets_footer) = $this->assetResolver->getJsAssets($assets, $optimize_js);
         $variables['scripts'] = $this->jsCollectionRenderer->render($js_assets_header);
         $variables['scripts_bottom'] = $this->jsCollectionRenderer->render($js_assets_footer);
     }
     return $variables;
 }
コード例 #22
0
 /**
  * Add Cache-Control and Expires headers to a cacheable response.
  *
  * @param \Symfony\Component\HttpFoundation\Response $response
  *   A response object.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   A request object.
  */
 protected function setResponseCacheable(Response $response, Request $request)
 {
     // HTTP/1.0 proxies do not support the Vary header, so prevent any caching
     // by sending an Expires date in the past. HTTP/1.1 clients ignore the
     // Expires header if a Cache-Control: max-age directive is specified (see
     // RFC 2616, section 14.9.3).
     if (!$response->headers->has('Expires')) {
         $this->setExpiresNoCache($response);
     }
     $max_age = $this->config->get('cache.page.max_age');
     $response->headers->set('Cache-Control', 'public, max-age=' . $max_age);
     // In order to support HTTP cache-revalidation, ensure that there is a
     // Last-Modified and an ETag header on the response.
     if (!$response->headers->has('Last-Modified')) {
         $timestamp = REQUEST_TIME;
         $response->setLastModified(new \DateTime(gmdate(DateTimePlus::RFC7231, REQUEST_TIME)));
     } else {
         $timestamp = $response->getLastModified()->getTimestamp();
     }
     $response->setEtag($timestamp);
     // Allow HTTP proxies to cache pages for anonymous users without a session
     // cookie. The Vary header is used to indicates the set of request-header
     // fields that fully determines whether a cache is permitted to use the
     // response to reply to a subsequent request for a given URL without
     // revalidation.
     if (!$response->hasVary() && !Settings::get('omit_vary_cookie')) {
         $response->setVary('Cookie', FALSE);
     }
 }
コード例 #23
0
 /**
  * {@inheritdoc}
  */
 function render(ResultRow $values)
 {
     // Ensure Disqus comments are available on the entity and user has access to edit this entity.
     $entity = $this->getEntity($values);
     if (!$entity) {
         return;
     }
     $field = $this->disqusManager->getFields($entity->getEntityTypeId());
     if (!$entity->hasField(key($field))) {
         return;
     }
     if ($entity->get(key($field))->status && $this->currentUser->hasPermission('view disqus comments')) {
         // Build a renderable array for the link.
         $links['disqus_comments_num'] = array('title' => t('Comments'), 'url' => $entity->urlInfo(), 'fragment' => 'disqus_thread', 'attributes' => array('data-disqus-identifier' => "{$entity->getEntityTypeId()}/{$entity->id()}"));
         $content = array('#theme' => 'links', '#links' => $links, '#attributes' => array('class' => array('links', 'inline')));
         /**
          * This attaches disqus.js specified in the disqus.libraries.yml file,
          * which will look for the DOM variable disqusComments which is set below.
          * When found, the disqus javascript api replaces the html element with
          * the attribute: "data-disqus-identifier" and replaces the element with
          * the number of comments on the entity.
          */
         $content['#attached']['library'][] = 'disqus/disqus';
         $content['#attached']['drupalSettings']['disqusComments'] = $this->config->get('disqus_domain');
         return $content;
     }
 }
コード例 #24
0
ファイル: CommentManager.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function forbiddenMessage(EntityInterface $entity, $field_name)
 {
     if (!isset($this->authenticatedCanPostComments)) {
         // We only output a link if we are certain that users will get the
         // permission to post comments by logging in.
         $this->authenticatedCanPostComments = $this->entityManager->getStorage('user_role')->load(RoleInterface::AUTHENTICATED_ID)->hasPermission('post comments');
     }
     if ($this->authenticatedCanPostComments) {
         // We cannot use the redirect.destination service here because these links
         // sometimes appear on /node and taxonomy listing pages.
         if ($entity->get($field_name)->getFieldDefinition()->getSetting('form_location') == CommentItemInterface::FORM_SEPARATE_PAGE) {
             $comment_reply_parameters = ['entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), 'field_name' => $field_name];
             $destination = array('destination' => $this->url('comment.reply', $comment_reply_parameters, array('fragment' => 'comment-form')));
         } else {
             $destination = array('destination' => $entity->url('canonical', array('fragment' => 'comment-form')));
         }
         if ($this->userConfig->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
             // Users can register themselves.
             return $this->t('<a href=":login">Log in</a> or <a href=":register">register</a> to post comments', array(':login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination)), ':register' => $this->urlGenerator->generateFromRoute('user.register', array(), array('query' => $destination))));
         } else {
             // Only admins can add new users, no public registration.
             return $this->t('<a href=":login">Log in</a> to post comments', array(':login' => $this->urlGenerator->generateFromRoute('user.login', array(), array('query' => $destination))));
         }
     }
     return '';
 }
コード例 #25
0
ファイル: ConfigTest.php プロジェクト: Nikola-xiii/d8intranet
 /**
  * Asserts all original config data equals $data provided.
  *
  * @param array $data
  *   Config data to be checked.
  * @param bool $apply_overrides
  *   Apply any overrides to the original data.
  */
 public function assertOriginalConfigDataEquals($data, $apply_overrides)
 {
     foreach ($data as $key => $value) {
         $config_value = $this->config->getOriginal($key, $apply_overrides);
         $this->assertEquals($value, $config_value);
     }
 }
コード例 #26
0
ファイル: MailManager.php プロジェクト: anatalsceo/en-classe
 /**
  * Overrides PluginManagerBase::getInstance().
  *
  * Returns an instance of the mail plugin to use for a given message ID.
  *
  * The selection of a particular implementation is controlled via the config
  * 'system.mail.interface', which is a keyed array.  The default
  * implementation is the mail plugin whose ID is the value of 'default' key. A
  * more specific match first to key and then to module will be used in
  * preference to the default. To specify a different plugin for all mail sent
  * by one module, set the plugin ID as the value for the key corresponding to
  * the module name. To specify a plugin for a particular message sent by one
  * module, set the plugin ID as the value for the array key that is the
  * message ID, which is "${module}_${key}".
  *
  * For example to debug all mail sent by the user module by logging it to a
  * file, you might set the variable as something like:
  *
  * @code
  * array(
  *   'default' => 'php_mail',
  *   'user' => 'devel_mail_log',
  * );
  * @endcode
  *
  * Finally, a different system can be specified for a specific message ID (see
  * the $key param), such as one of the keys used by the contact module:
  *
  * @code
  * array(
  *   'default' => 'php_mail',
  *   'user' => 'devel_mail_log',
  *   'contact_page_autoreply' => 'null_mail',
  * );
  * @endcode
  *
  * Other possible uses for system include a mail-sending plugin that actually
  * sends (or duplicates) each message to SMS, Twitter, instant message, etc,
  * or a plugin that queues up a large number of messages for more efficient
  * bulk sending or for sending via a remote gateway so as to reduce the load
  * on the local server.
  *
  * @param array $options
  *   An array with the following key/value pairs:
  *   - module: (string) The module name which was used by drupal_mail() to
  *     invoke hook_mail().
  *   - key: (string) A key to identify the email sent. The final message ID
  *     is a string represented as {$module}_{$key}.
  *
  * @return \Drupal\Core\Mail\MailInterface
  *   A mail plugin instance.
  *
  * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
  */
 public function getInstance(array $options)
 {
     $module = $options['module'];
     $key = $options['key'];
     $message_id = $module . '_' . $key;
     $configuration = $this->mailConfig->get('interface');
     // Look for overrides for the default mail plugin, starting from the most
     // specific message_id, and falling back to the module name.
     if (isset($configuration[$message_id])) {
         $plugin_id = $configuration[$message_id];
     } elseif (isset($configuration[$module])) {
         $plugin_id = $configuration[$module];
     } else {
         $plugin_id = $configuration['default'];
     }
     if (empty($this->instances[$plugin_id])) {
         $plugin = $this->createInstance($plugin_id);
         if (is_subclass_of($plugin, '\\Drupal\\Core\\Mail\\MailInterface')) {
             $this->instances[$plugin_id] = $plugin;
         } else {
             throw new InvalidPluginDefinitionException($plugin_id, String::format('Class %class does not implement interface %interface', array('%class' => get_class($plugin), '%interface' => 'Drupal\\Core\\Mail\\MailInterface')));
         }
     }
     return $this->instances[$plugin_id];
 }
コード例 #27
0
 /**
  * Provides configuration schema.
  *
  * @param string $name
  *   A string config key.
  *
  * @return array|null
  */
 public function getConfigSchema($name)
 {
     $old_state = $this->configFactory->getOverrideState();
     $this->configFactory->setOverrideState(FALSE);
     $config_schema = $this->typedConfigManager->get($name);
     $this->configFactory->setOverrideState($old_state);
     return $config_schema;
 }
コード例 #28
0
 /**
  * Set up the tests and create the users.
  */
 public function setUp()
 {
     parent::setUp();
     // Create object with configuration.
     $this->config = \Drupal::configFactory()->getEditable('geshifilter.settings');
     // And set the path to the geshi library.
     $this->config->set('geshi_dir', '/libraries/geshi');
     $settings = array('type' => 'geshifilter_content_type', 'name' => 'Geshifilter Content');
     $this->drupalCreateContentType($settings);
     // Create a filter admin user.
     $permissions = array('administer filters', 'access administration pages', 'administer site configuration');
     $this->filterAdminUser = $this->drupalCreateUser($permissions);
     // Log in with filter admin user.
     $this->drupalLogin($this->filterAdminUser);
     // Add an text format with only geshi filter.
     $this->createTextFormat('geshifilter_text_format', array('filter_geshifilter'));
 }
コード例 #29
0
 /**
  * write configuration back to files.
  *
  * @param \Drupal\Core\Config\Config $config
  *   The config object.
  * @param array $file_names
  *   The file names to which the configuration should be written.
  */
 public function writeBackConfig(Config $config, array $file_names)
 {
     if ($file_names) {
         $data = $config->get();
         $config_name = $config->getName();
         if ($entity_type_id = $this->configManager->getEntityTypeIdByName($config_name)) {
             unset($data['uuid']);
         }
         foreach ($file_names as $file_name) {
             try {
                 file_put_contents($file_name, (new InstallStorage())->encode($data));
             } catch (DumpException $e) {
                 // Do nothing. What could we do?
             }
         }
     }
 }
コード例 #30
0
 /**
  * Will test the redirects.
  */
 public function testRedirects()
 {
     // Test alias normalization.
     $this->config->set('normalize_aliases', TRUE)->save();
     $this->assertRedirect('node/' . $this->node->id(), 'test-node');
     $this->assertRedirect('Test-node', 'test-node');
     $this->config->set('normalize_aliases', FALSE)->save();
     $this->assertRedirect('node/' . $this->node->id(), NULL, 'HTTP/1.1 200 OK');
     $this->assertRedirect('Test-node', NULL, 'HTTP/1.1 200 OK');
     // Test deslashing.
     $this->config->set('deslash', TRUE)->save();
     $this->assertRedirect('test-node/', 'test-node');
     $this->config->set('deslash', FALSE)->save();
     $this->assertRedirect('test-node/', NULL, 'HTTP/1.1 200 OK');
     // Test front page redirects.
     $this->config->set('frontpage_redirect', TRUE)->save();
     $this->config('system.site')->set('page.front', '/node')->save();
     $this->assertRedirect('node', '<front>');
     // Test front page redirects with an alias.
     \Drupal::service('path.alias_storage')->save('/node', '/node-alias');
     $this->assertRedirect('node-alias', '<front>');
     $this->config->set('frontpage_redirect', FALSE)->save();
     $this->assertRedirect('node', NULL, 'HTTP/1.1 200 OK');
     $this->assertRedirect('node-alias', NULL, 'HTTP/1.1 200 OK');
     // Test post request.
     $this->config->set('normalize_aliases', TRUE)->save();
     $this->drupalPost('Test-node', 'application/json', array());
     // Does not do a redirect, stays in the same path.
     $this->assertEqual(basename($this->getUrl()), 'Test-node');
     // Test the access checking.
     $this->config->set('normalize_aliases', TRUE)->save();
     $this->config->set('access_check', TRUE)->save();
     $this->assertRedirect('admin/config/system/site-information', NULL, 'HTTP/1.1 403 Forbidden');
     $this->config->set('access_check', FALSE)->save();
     // @todo - here it seems that the access check runs prior to our redirecting
     //   check why so and enable the test.
     //$this->assertRedirect('admin/config/system/site-information', 'site-info');
     // Login as user with admin privileges.
     $this->drupalLogin($this->adminUser);
     // Test ignoring admin paths.
     $this->config->set('ignore_admin_path', FALSE)->save();
     $this->assertRedirect('admin/config/system/site-information', 'site-info');
     $this->config->set('ignore_admin_path', TRUE)->save();
     $this->assertRedirect('admin/config/system/site-information', NULL, 'HTTP/1.1 200 OK');
 }