コード例 #1
0
 /**
  * Alters base_route and parent_id into the views local tasks.
  */
 public function alterLocalTasks(&$local_tasks)
 {
     $view_route_names = $this->state->get('views.view_route_names');
     foreach ($this->getApplicableMenuViews() as $pair) {
         /** @var $executable \Drupal\views\ViewExecutable */
         list($executable, $display_id) = $pair;
         $executable->setDisplay($display_id);
         $menu = $executable->display_handler->getOption('menu');
         // We already have set the base_route for default tabs.
         if (in_array($menu['type'], array('tab'))) {
             $plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
             $view_route_name = $view_route_names[$executable->storage->id() . '.' . $display_id];
             // Don't add a local task for views which override existing routes.
             if ($view_route_name != $plugin_id) {
                 unset($local_tasks[$plugin_id]);
                 continue;
             }
             // Find out the parent route.
             // @todo Find out how to find both the root and parent tab.
             $path = $executable->display_handler->getPath();
             $split = explode('/', $path);
             array_pop($split);
             $path = implode('/', $split);
             $pattern = '/' . str_replace('%', '{}', $path);
             if ($routes = $this->routeProvider->getRoutesByPattern($pattern)) {
                 foreach ($routes->all() as $name => $route) {
                     $local_tasks['views_view:' . $plugin_id]['base_route'] = $name;
                     // Skip after the first found route.
                     break;
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state) {
   $settings = $this->config('rest_api_doc.settings');
   $enabled_route_names = $settings->get('routes');
   $available_route_names = $this->state->get('rest_api_doc.rest_route_names');
   if (empty($available_route_names)) {
     return array(
       'no_routes' => array(
         '#markup' => $this->t('No REST enabled routes exist, please configure your REST end-points'),
       ),
     );
   }
   else {
     $routes = $this->routeProvider->getRoutesByNames($available_route_names);
     $descriptions = array();
     foreach ($routes as $route_name => $route) {
       $descriptions[$route_name] = $route_name . ' (' . $route->getPath() . ')';
     }
     $form['routes'] = array(
       '#type' => 'checkboxes',
       '#title' => $this->t('Enabled routes'),
       '#description' => $this->t('Provide documentation for the following route names'),
       '#options' => array_combine($available_route_names, $descriptions),
       '#default_value' => $enabled_route_names,
     );
     $form['overview'] = array(
       '#type' => 'textarea',
       '#default_value' => $settings->get('overview'),
       '#title' => $this->t('REST API overview'),
       '#description' => $this->t('Description to show on summary page. You may use site-wide tokens and some markup.'),
     );
   }
   return parent::buildForm($form, $form_state);
 }
コード例 #3
0
  /**
   * Tests altering and finished event.
   *
   * @covers ::onRouteAlter
   * @covers ::onRouteFinished
   */
  public function testSubscribing() {

    // Ensure that onRouteFinished can be called without throwing notices
    // when no path roots got set.
    $this->pathRootsSubscriber->onRouteFinished();

    $route_collection = new RouteCollection();
    $route_collection->add('test_route1', new Route('/test/bar'));
    $route_collection->add('test_route2', new Route('/test/baz'));
    $route_collection->add('test_route3', new Route('/test2/bar/baz'));

    $event = new RouteBuildEvent($route_collection, 'provider');
    $this->pathRootsSubscriber->onRouteAlter($event);

    $route_collection = new RouteCollection();
    $route_collection->add('test_route4', new Route('/test1/bar'));
    $route_collection->add('test_route5', new Route('/test2/baz'));
    $route_collection->add('test_route6', new Route('/test2/bar/baz'));

    $event = new RouteBuildEvent($route_collection, 'provider');
    $this->pathRootsSubscriber->onRouteAlter($event);

    $this->state->expects($this->once())
      ->method('set')
      ->with('router.path_roots', array('test', 'test2', 'test1'));

    $this->pathRootsSubscriber->onRouteFinished();
  }
コード例 #4
0
ファイル: ReportWorkerBase.php プロジェクト: dropdog/play
 /**
  * Simple reporter log and display information about the queue.
  *
  * @param int $worker
  *   Worker number.
  * @param object $item
  *   The $item which was stored in the cron queue.
  */
 protected function reportWork($worker, $item)
 {
     if ($this->state->get('cron_example_show_status_message')) {
         drupal_set_message($this->t('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]));
     }
     $this->logger->get('cron_example')->info('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]);
 }
コード例 #5
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;
 }
コード例 #6
0
ファイル: EventSubscriber.php プロジェクト: ddrozdik/dmaps
 /**
  * Reacts to the ConfigEvents::COLLECTION_NAMES event.
  *
  * @param \Drupal\Core\Config\ConfigCollectionInfo $collection_info
  *   The configuration collection names event.
  */
 public function addCollections(ConfigCollectionInfo $collection_info)
 {
     $collections = $this->state->get('config_collection_install_test.collection_names', array());
     foreach ($collections as $collection) {
         $collection_info->addCollection($collection);
     }
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function processInbound($path, Request $request)
 {
     if ($this->state->get('update_script_test_broken_inbound', FALSE)) {
         throw new \RuntimeException();
     } else {
         return $path;
     }
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function render(array $js_assets)
 {
     $elements = array();
     // A dummy query-string is added to filenames, to gain control over
     // browser-caching. The string changes on every update or full cache
     // flush, forcing browsers to load a new copy of the files, as the
     // URL changed. Files that should not be cached (see _drupal_add_js())
     // get REQUEST_TIME as query-string instead, to enforce reload on every
     // page request.
     $default_query_string = $this->state->get('system.css_js_query_string') ?: '0';
     // For inline JavaScript to validate as XHTML, all JavaScript containing
     // XHTML needs to be wrapped in CDATA. To make that backwards compatible
     // with HTML 4, we need to comment out the CDATA-tag.
     $embed_prefix = "\n<!--//--><![CDATA[//><!--\n";
     $embed_suffix = "\n//--><!]]>\n";
     // Defaults for each SCRIPT element.
     $element_defaults = array('#type' => 'html_tag', '#tag' => 'script', '#value' => '');
     // Loop through all JS assets.
     foreach ($js_assets as $js_asset) {
         // Element properties that do not depend on JS asset type.
         $element = $element_defaults;
         $element['#browsers'] = $js_asset['browsers'];
         // Element properties that depend on item type.
         switch ($js_asset['type']) {
             case 'setting':
                 $element['#value_prefix'] = $embed_prefix;
                 $element['#value'] = 'var drupalSettings = ' . Json::encode(drupal_merge_js_settings($js_asset['data'])) . ";";
                 $element['#value_suffix'] = $embed_suffix;
                 break;
             case 'inline':
                 $element['#value_prefix'] = $embed_prefix;
                 $element['#value'] = $js_asset['data'];
                 $element['#value_suffix'] = $embed_suffix;
                 break;
             case 'file':
                 $query_string = empty($js_asset['version']) ? $default_query_string : 'v=' . $js_asset['version'];
                 $query_string_separator = strpos($js_asset['data'], '?') !== FALSE ? '&' : '?';
                 $element['#attributes']['src'] = file_create_url($js_asset['data']);
                 // Only add the cache-busting query string if this isn't an aggregate
                 // file.
                 if (!isset($js_asset['preprocessed'])) {
                     $element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : REQUEST_TIME);
                 }
                 break;
             case 'external':
                 $element['#attributes']['src'] = $js_asset['data'];
                 break;
             default:
                 throw new \Exception('Invalid JS asset type.');
         }
         // Attributes may only be set if this script is output independently.
         if (!empty($element['#attributes']['src']) && !empty($js_asset['attributes'])) {
             $element['#attributes'] += $js_asset['attributes'];
         }
         $elements[] = $element;
     }
     return $elements;
 }
コード例 #9
0
 /**
  * Loads menu path roots to prepopulate cache.
  */
 protected function loadMenuPathRoots()
 {
     if ($roots = $this->state->get('router.path_roots')) {
         foreach ($roots as $root) {
             $this->storage[$root] = NULL;
             $this->persist($root);
         }
     }
 }
コード例 #10
0
ファイル: EntityComment.php プロジェクト: jover/drupalcap
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     if ($row->isStub() && ($state = $this->state->get('comment.maintain_entity_statistics', 0))) {
         $this->state->set('comment.maintain_entity_statistics', 0);
     }
     $return = parent::import($row, $old_destination_id_values);
     if ($row->isStub() && $state) {
         $this->state->set('comment.maintain_entity_statistics', $state);
     }
     return $return;
 }
コード例 #11
0
ファイル: MaintenanceMode.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     if (!$this->state->get('system.maintenance_mode')) {
         return FALSE;
     }
     if ($route = $route_match->getRouteObject()) {
         if ($route->getOption('_maintenance_access')) {
             return FALSE;
         }
     }
     return TRUE;
 }
コード例 #12
0
ファイル: CronForm.php プロジェクト: anatalsceo/en-classe
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('system.cron');
     $form['description'] = array('#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>');
     $form['run'] = array('#type' => 'submit', '#value' => t('Run cron'), '#submit' => array(array($this, 'submitCron')));
     $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => $this->dateFormatter->formatInterval(REQUEST_TIME - $this->state->get('system.cron_last')))) . '</p>';
     $form['status'] = array('#markup' => $status);
     $form['cron_url'] = array('#markup' => '<p>' . t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . $this->state->get('system.cron_key'), array('absolute' => TRUE)))) . '</p>');
     $form['cron'] = array('#title' => t('Cron settings'), '#type' => 'details', '#open' => TRUE);
     $options = array(3600, 10800, 21600, 43200, 86400, 604800);
     $form['cron']['cron_safe_threshold'] = array('#type' => 'select', '#title' => t('Run cron every'), '#description' => t('More information about setting up scheduled tasks can be found by <a href="@url">reading the cron tutorial on drupal.org</a>.', array('@url' => url('http://drupal.org/cron'))), '#default_value' => $config->get('threshold.autorun'), '#options' => array(0 => t('Never')) + array_map(array($this->dateFormatter, 'formatInterval'), array_combine($options, $options)));
     return parent::buildForm($form, $form_state);
 }
コード例 #13
0
ファイル: SqlBase.php プロジェクト: frankcr/sftw8
 /**
  * Gets the database connection object.
  *
  * @return \Drupal\Core\Database\Connection
  *   The database connection.
  */
 public function getDatabase()
 {
     if (!isset($this->database)) {
         // See if the database info is in state - if not, fallback to
         // configuration.
         if (isset($this->configuration['database_state_key'])) {
             $this->database = $this->setUpDatabase($this->state->get($this->configuration['database_state_key']));
         } else {
             $this->database = $this->setUpDatabase($this->configuration);
         }
     }
     return $this->database;
 }
コード例 #14
0
ファイル: CronForm.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['description'] = array('#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>');
     $form['run'] = array('#type' => 'submit', '#value' => t('Run cron'));
     $status = '<p>' . $this->t('Last run: %time ago.', array('%time' => $this->dateFormatter->formatTimeDiffSince($this->state->get('system.cron_last')))) . '</p>';
     $form['status'] = array('#markup' => $status);
     $cron_url = $this->url('system.cron', array('key' => $this->state->get('system.cron_key')), array('absolute' => TRUE));
     $form['cron_url'] = array('#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', array(':cron' => $cron_url, '@cron' => $cron_url)) . '</p>');
     if (!$this->moduleHandler->moduleExists('automated_cron')) {
         $form['cron'] = array('#markup' => $this->t('Enable the <em>Automated Cron</em> module to allow cron execution at the end of a server response.'));
     }
     return $form;
 }
コード例 #15
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $key = $input->getArgument('key');
     if ($key) {
         $io->info($key);
         $io->writeln(Yaml::encode($this->state->get($key)));
         return 0;
     }
     $tableHeader = [$this->trans('commands.state.debug.messages.key')];
     $keyStoreStates = array_keys($this->keyValue->get('state')->getAll());
     $io->table($tableHeader, $keyStoreStates);
     return 0;
 }
コード例 #16
0
ファイル: MatcherDumper.php プロジェクト: 318io/318-io
 /**
  * Dumps a set of routes to the router table in the database.
  *
  * Available options:
  * - provider: The route grouping that is being dumped. All existing
  *   routes with this provider will be deleted on dump.
  * - base_class: The base class name.
  *
  * @param array $options
  *   An array of options.
  */
 public function dump(array $options = array())
 {
     // Convert all of the routes into database records.
     // Accumulate the menu masks on top of any we found before.
     $masks = array_flip($this->state->get('routing.menu_masks.' . $this->tableName, array()));
     // Delete any old records first, then insert the new ones. That avoids
     // stale data. The transaction makes it atomic to avoid unstable router
     // states due to random failures.
     $transaction = $this->connection->startTransaction();
     try {
         // We don't use truncate, because it is not guaranteed to be transaction
         // safe.
         try {
             $this->connection->delete($this->tableName)->execute();
         } catch (\Exception $e) {
             $this->ensureTableExists();
         }
         // Split the routes into chunks to avoid big INSERT queries.
         $route_chunks = array_chunk($this->routes->all(), 50, TRUE);
         foreach ($route_chunks as $routes) {
             $insert = $this->connection->insert($this->tableName)->fields(array('name', 'fit', 'path', 'pattern_outline', 'number_parts', 'route'));
             $names = array();
             foreach ($routes as $name => $route) {
                 /** @var \Symfony\Component\Routing\Route $route */
                 $route->setOption('compiler_class', '\\Drupal\\Core\\Routing\\RouteCompiler');
                 /** @var \Drupal\Core\Routing\CompiledRoute $compiled */
                 $compiled = $route->compile();
                 // The fit value is a binary number which has 1 at every fixed path
                 // position and 0 where there is a wildcard. We keep track of all such
                 // patterns that exist so that we can minimize the number of path
                 // patterns we need to check in the RouteProvider.
                 $masks[$compiled->getFit()] = 1;
                 $names[] = $name;
                 $values = array('name' => $name, 'fit' => $compiled->getFit(), 'path' => $route->getPath(), 'pattern_outline' => $compiled->getPatternOutline(), 'number_parts' => $compiled->getNumParts(), 'route' => serialize($route));
                 $insert->values($values);
             }
             // Insert all new routes.
             $insert->execute();
         }
     } catch (\Exception $e) {
         $transaction->rollback();
         watchdog_exception('Routing', $e);
         throw $e;
     }
     // Sort the masks so they are in order of descending fit.
     $masks = array_keys($masks);
     rsort($masks);
     $this->state->set('routing.menu_masks.' . $this->tableName, $masks);
     $this->routes = NULL;
 }
コード例 #17
0
 /**
  * Tests that changes to the info file are picked up.
  */
 public function testChanges()
 {
     $this->themeHandler->install(array('test_theme'));
     $this->themeHandler->setDefault('test_theme');
     $this->themeManager->resetActiveTheme();
     $active_theme = $this->themeManager->getActiveTheme();
     // Make sure we are not testing the wrong theme.
     $this->assertEqual('test_theme', $active_theme->getName());
     $this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
     // @see theme_test_system_info_alter()
     $this->state->set('theme_test.modify_info_files', TRUE);
     drupal_flush_all_caches();
     $active_theme = $this->themeManager->getActiveTheme();
     $this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());
 }
コード例 #18
0
 /**
  * Utility submit function to reset the demo.
  *
  * @param array $form
  *   FormAPI form.
  * @param FormStateInterface $form_state
  *   FormAPI form state.
  *
  * @todo Note this does NOT clear any managed file references in Drupal's DB.
  *       It might be a good idea to add this.
  */
 public function handleResetSession(array &$form, FormStateInterface $form_state)
 {
     $this->state->delete('file_example_default_file');
     $this->state->delete('file_example_default_directory');
     $this->clearStoredData();
     drupal_set_message('Session reset.');
 }
コード例 #19
0
ファイル: IndexTaskManager.php プロジェクト: jkyto/agolf
 /**
  * Retrieves the current state for a specific index.
  *
  * @param \Drupal\search_api\IndexInterface $index
  *   The index whose state should be retrieved.
  * @param bool $provide_default
  *   Whether to provide a default state array if there was no state saved.
  *
  * @return array|null
  *   An associative array with information about the state of the given index:
  *   - status: 0 if no tracking operation is currently in progress, 1 if there
  *     is.
  *   - page: If status is 1, the next page of items to process for tracking.
  *   Or NULL if there was no saved state and $provide_default is FALSE.
  */
 protected function getIndexState(IndexInterface $index, $provide_default = TRUE) {
   $default = array(
     'status' => 0,
     'pages' => array(),
   );
   return $this->state->get($this->getIndexStateKey($index), $provide_default ? $default : NULL);
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $modules = $input->getArgument('module');
     if (!$this->lock->acquire('cron', 900.0)) {
         $io->warning($this->trans('commands.cron.execute.messages.lock'));
         return 1;
     }
     if (in_array('all', $modules)) {
         $modules = $this->moduleHandler->getImplementations('cron');
     }
     foreach ($modules as $module) {
         if (!$this->moduleHandler->implementsHook($module, 'cron')) {
             $io->warning(sprintf($this->trans('commands.cron.execute.messages.module-invalid'), $module));
             continue;
         }
         try {
             $io->info(sprintf($this->trans('commands.cron.execute.messages.executing-cron'), $module));
             $this->moduleHandler->invoke($module, 'cron');
         } catch (\Exception $e) {
             watchdog_exception('cron', $e);
             $io->error($e->getMessage());
         }
     }
     $this->state->set('system.cron_last', REQUEST_TIME);
     $this->lock->release('cron');
     $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
     $io->success($this->trans('commands.cron.execute.messages.success'));
     return 0;
 }
コード例 #21
0
ファイル: SiteConfigureForm.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->config('system.site')->set('name', (string) $form_state->getValue('site_name'))->set('mail', (string) $form_state->getValue('site_mail'))->save(TRUE);
     $this->config('system.date')->set('timezone.default', (string) $form_state->getValue('date_default_timezone'))->set('country.default', (string) $form_state->getValue('site_default_country'))->save(TRUE);
     $account_values = $form_state->getValue('account');
     // Enable update.module if this option was selected.
     $update_status_module = $form_state->getValue('update_status_module');
     if ($update_status_module[1]) {
         $this->moduleInstaller->install(array('file', 'update'), FALSE);
         // Add the site maintenance account's email address to the list of
         // addresses to be notified when updates are available, if selected.
         if ($update_status_module[2]) {
             // Reset the configuration factory so it is updated with the new module.
             $this->resetConfigFactory();
             $this->config('update.settings')->set('notification.emails', array($account_values['mail']))->save(TRUE);
         }
     }
     // We precreated user 1 with placeholder values. Let's save the real values.
     $account = $this->userStorage->load(1);
     $account->init = $account->mail = $account_values['mail'];
     $account->roles = $account->getRoles();
     $account->activate();
     $account->timezone = $form_state->getValue('date_default_timezone');
     $account->pass = $account_values['pass'];
     $account->name = $account_values['name'];
     $account->save();
     // Record when this install ran.
     $this->state->set('install_time', $_SERVER['REQUEST_TIME']);
 }
コード例 #22
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->moduleHandler->loadInclude('locale', 'fetch.inc');
     $this->moduleHandler->loadInclude('locale', 'bulk.inc');
     $langcodes = array_filter($form_state->getValue('langcodes'));
     $projects = array_filter($form_state->getValue('projects_update'));
     // Set the translation import options. This determines if existing
     // translations will be overwritten by imported strings.
     $options = _locale_translation_default_update_options();
     // If the status was updated recently we can immediately start fetching the
     // translation updates. If the status is expired we clear it an run a batch to
     // update the status and then fetch the translation updates.
     $last_checked = $this->state->get('locale.translation_last_checked');
     if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
         locale_translation_clear_status();
         $batch = locale_translation_batch_update_build(array(), $langcodes, $options);
         batch_set($batch);
     } else {
         // Set a batch to download and import translations.
         $batch = locale_translation_batch_fetch_build($projects, $langcodes, $options);
         batch_set($batch);
         // Set a batch to update configuration as well.
         if ($batch = locale_config_batch_update_components($options, $langcodes)) {
             batch_set($batch);
         }
     }
 }
コード例 #23
0
 /**
  * {@inheritdoc}
  */
 public function update(CommentInterface $comment)
 {
     // Allow bulk updates and inserts to temporarily disable the maintenance of
     // the {comment_entity_statistics} table.
     if (!$this->state->get('comment.maintain_entity_statistics')) {
         return;
     }
     $query = $this->database->select('comment_field_data', 'c');
     $query->addExpression('COUNT(cid)');
     $count = $query->condition('c.entity_id', $comment->getCommentedEntityId())->condition('c.entity_type', $comment->getCommentedEntityTypeId())->condition('c.field_name', $comment->getFieldName())->condition('c.status', CommentInterface::PUBLISHED)->condition('default_langcode', 1)->execute()->fetchField();
     if ($count > 0) {
         // Comments exist.
         $last_reply = $this->database->select('comment_field_data', 'c')->fields('c', array('cid', 'name', 'changed', 'uid'))->condition('c.entity_id', $comment->getCommentedEntityId())->condition('c.entity_type', $comment->getCommentedEntityTypeId())->condition('c.field_name', $comment->getFieldName())->condition('c.status', CommentInterface::PUBLISHED)->condition('default_langcode', 1)->orderBy('c.created', 'DESC')->range(0, 1)->execute()->fetchObject();
         // Use merge here because entity could be created before comment field.
         $this->database->merge('comment_entity_statistics')->fields(array('cid' => $last_reply->cid, 'comment_count' => $count, 'last_comment_timestamp' => $last_reply->changed, 'last_comment_name' => $last_reply->uid ? '' : $last_reply->name, 'last_comment_uid' => $last_reply->uid))->keys(array('entity_id' => $comment->getCommentedEntityId(), 'entity_type' => $comment->getCommentedEntityTypeId(), 'field_name' => $comment->getFieldName()))->execute();
     } else {
         // Comments do not exist.
         $entity = $comment->getCommentedEntity();
         // Get the user ID from the entity if it's set, or default to the
         // currently logged in user.
         if ($entity instanceof EntityOwnerInterface) {
             $last_comment_uid = $entity->getOwnerId();
         }
         if (!isset($last_comment_uid)) {
             // Default to current user when entity does not implement
             // EntityOwnerInterface or author is not set.
             $last_comment_uid = $this->currentUser->id();
         }
         $this->database->update('comment_entity_statistics')->fields(array('cid' => 0, 'comment_count' => 0, 'last_comment_timestamp' => $entity instanceof EntityChangedInterface ? $entity->getChangedTime() : REQUEST_TIME, 'last_comment_name' => '', 'last_comment_uid' => $last_comment_uid))->condition('entity_id', $comment->getCommentedEntityId())->condition('entity_type', $comment->getCommentedEntityTypeId())->condition('field_name', $comment->getFieldName())->execute();
     }
     // Reset the cache of the commented entity so that when the entity is loaded
     // the next time, the statistics will be loaded again.
     $this->entityManager->getStorage($comment->getCommentedEntityTypeId())->resetCache(array($comment->getCommentedEntityId()));
 }
コード例 #24
0
 /**
  * Tests a CSS asset group with the invalid 'type' => 'internal'.
  */
 function testRenderInvalidType()
 {
     $this->state->expects($this->once())->method('get')->with('system.css_js_query_string')->will($this->returnValue(NULL));
     $this->setExpectedException('Exception', 'Invalid CSS asset type.');
     $css_group = array('group' => 0, 'type' => 'internal', 'media' => 'all', 'preprocess' => TRUE, 'browsers' => array(), 'data' => 'http://example.com/popular.js');
     $this->renderer->render($css_group);
 }
コード例 #25
0
 /**
  * Returns the entity_test hook invocation info.
  *
  * @return array
  *   An associative array of arbitrary hook data keyed by hook name.
  */
 protected function getHooksInfo()
 {
     $key = 'entity_test.hooks';
     $hooks = $this->state->get($key);
     $this->state->set($key, array());
     return $hooks;
 }
コード例 #26
0
 /**
  * Tests the onAlterRoutes method.
  *
  * @see \Drupal\views\EventSubscriber\RouteSubscriber::onAlterRoutes()
  */
 public function testOnAlterRoutes()
 {
     $collection = new RouteCollection();
     // The first route will be overridden later.
     $collection->add('test_route', new Route('test_route', array('_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController')));
     $route_2 = new Route('test_route/example', array('_controller' => 'Drupal\\Tests\\Core\\Controller\\TestController'));
     $collection->add('test_route_2', $route_2);
     $route_event = new RouteBuildEvent($collection, 'views');
     list($view, $executable, $display_1, $display_2) = $this->setupMocks();
     // The page_1 display overrides an existing route, so the dynamicRoutes
     // should only call the second display.
     $display_1->expects($this->once())->method('collectRoutes')->willReturnCallback(function () use($collection) {
         $collection->add('views.test_id.page_1', new Route('test_route', ['_content' => 'Drupal\\views\\Routing\\ViewPageController']));
         return ['test_id.page_1' => 'views.test_id.page_1'];
     });
     $display_1->expects($this->once())->method('alterRoutes')->willReturn(['test_id.page_1' => 'test_route']);
     $display_2->expects($this->once())->method('collectRoutes')->willReturnCallback(function () use($collection) {
         $collection->add('views.test_id.page_2', new Route('test_route', ['_content' => 'Drupal\\views\\Routing\\ViewPageController']));
         return ['test_id.page_2' => 'views.test_id.page_2'];
     });
     $display_2->expects($this->once())->method('alterRoutes')->willReturn([]);
     // Ensure that even both the collectRoutes() and alterRoutes() methods
     // are called on the displays, we ensure that the route first defined by
     // views is dropped.
     $this->routeSubscriber->routes();
     $this->assertNull($this->routeSubscriber->onAlterRoutes($route_event));
     $this->state->expects($this->once())->method('set')->with('views.view_route_names', array('test_id.page_1' => 'test_route', 'test_id.page_2' => 'views.test_id.page_2'));
     $collection = $route_event->getRouteCollection();
     $this->assertEquals(['test_route', 'test_route_2', 'views.test_id.page_2'], array_keys($collection->all()));
     $this->routeSubscriber->routeRebuildFinished();
 }
コード例 #27
0
ファイル: JsCollectionRenderer.php プロジェクト: Wylbur/gj
 /**
  * {@inheritdoc}
  *
  * This class evaluates the aggregation enabled/disabled condition on a group
  * by group basis by testing whether an aggregate file has been made for the
  * group rather than by testing the site-wide aggregation setting. This allows
  * this class to work correctly even if modules have implemented custom
  * logic for grouping and aggregating files.
  */
 public function render(array $js_assets)
 {
     $elements = array();
     // A dummy query-string is added to filenames, to gain control over
     // browser-caching. The string changes on every update or full cache
     // flush, forcing browsers to load a new copy of the files, as the
     // URL changed. Files that should not be cached get REQUEST_TIME as
     // query-string instead, to enforce reload on every page request.
     $default_query_string = $this->state->get('system.css_js_query_string') ?: '0';
     // Defaults for each SCRIPT element.
     $element_defaults = array('#type' => 'html_tag', '#tag' => 'script', '#value' => '');
     // Loop through all JS assets.
     foreach ($js_assets as $js_asset) {
         // Element properties that do not depend on JS asset type.
         $element = $element_defaults;
         $element['#browsers'] = $js_asset['browsers'];
         // Element properties that depend on item type.
         switch ($js_asset['type']) {
             case 'setting':
                 $element['#attributes'] = array('type' => 'application/json', 'data-drupal-selector' => 'drupal-settings-json');
                 $element['#value'] = Json::encode($js_asset['data']);
                 break;
             case 'file':
                 $query_string = $js_asset['version'] == -1 ? $default_query_string : 'v=' . $js_asset['version'];
                 $query_string_separator = strpos($js_asset['data'], '?') !== FALSE ? '&' : '?';
                 $element['#attributes']['src'] = file_url_transform_relative(file_create_url($js_asset['data']));
                 // Only add the cache-busting query string if this isn't an aggregate
                 // file.
                 if (!isset($js_asset['preprocessed'])) {
                     $element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : REQUEST_TIME);
                 }
                 break;
             case 'external':
                 $element['#attributes']['src'] = $js_asset['data'];
                 break;
             default:
                 throw new \Exception('Invalid JS asset type.');
         }
         // Attributes may only be set if this script is output independently.
         if (!empty($element['#attributes']['src']) && !empty($js_asset['attributes'])) {
             $element['#attributes'] += $js_asset['attributes'];
         }
         $elements[] = $element;
     }
     return $elements;
 }
コード例 #28
0
ファイル: EventSubscriber.php プロジェクト: aWEBoLabs/taxi
 /**
  * Reacts to a config delete and records information in state for testing.
  *
  * @param \Drupal\Core\Config\ConfigCrudEvent $event
  */
 public function onConfigDelete(ConfigCrudEvent $event)
 {
     $config = $event->getConfig();
     if ($config->getName() == 'action.settings') {
         $value = $this->state->get('ConfigImportUITest.action.settings.delete', 0);
         $this->state->set('ConfigImportUITest.action.settings.delete', $value + 1);
     }
 }
コード例 #29
0
ファイル: ServerTaskUnitTest.php プロジェクト: jkyto/agolf
 /**
  * Retrieves the methods called on the test server.
  *
  * @param bool $reset
  *   (optional) Whether to reset the list after the called methods are
  *   retrieved.
  *
  * @return string[]
  *   The methods called on the test server since the last reset.
  */
 protected function getCalledServerMethods($reset = TRUE) {
   $key = 'search_api_test_backend.methods_called.' . $this->server->id();
   $methods_called = $this->state->get($key, array());
   if ($reset) {
     $this->state->delete($key);
   }
   return $methods_called;
 }
コード例 #30
0
 /**
  * {@inheritdoc}
  */
 public function delete(array $entities)
 {
     $return = parent::delete($entities);
     // Update the state of registered events.
     // @todo Should we trigger a container rebuild here as well? Might be a bit
     // expensive on every delete?
     $this->stateService->set('rules.registered_events', $this->getRegisteredEvents());
     return $return;
 }