Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/src/Plugin/Search/NodeSearch.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
11 use Drupal\Core\Entity\EntityManagerInterface; | 11 use Drupal\Core\Entity\EntityManagerInterface; |
12 use Drupal\Core\Extension\ModuleHandlerInterface; | 12 use Drupal\Core\Extension\ModuleHandlerInterface; |
13 use Drupal\Core\Form\FormStateInterface; | 13 use Drupal\Core\Form\FormStateInterface; |
14 use Drupal\Core\Language\LanguageInterface; | 14 use Drupal\Core\Language\LanguageInterface; |
15 use Drupal\Core\Language\LanguageManagerInterface; | 15 use Drupal\Core\Language\LanguageManagerInterface; |
16 use Drupal\Core\Messenger\MessengerInterface; | |
16 use Drupal\Core\Session\AccountInterface; | 17 use Drupal\Core\Session\AccountInterface; |
17 use Drupal\Core\Access\AccessibleInterface; | 18 use Drupal\Core\Access\AccessibleInterface; |
18 use Drupal\Core\Database\Query\Condition; | 19 use Drupal\Core\Database\Query\Condition; |
19 use Drupal\Core\Render\RendererInterface; | 20 use Drupal\Core\Render\RendererInterface; |
20 use Drupal\node\NodeInterface; | 21 use Drupal\node\NodeInterface; |
111 | 112 |
112 /** | 113 /** |
113 * A constant for setting and checking the query string. | 114 * A constant for setting and checking the query string. |
114 */ | 115 */ |
115 const ADVANCED_FORM = 'advanced-form'; | 116 const ADVANCED_FORM = 'advanced-form'; |
117 | |
118 /** | |
119 * The messenger. | |
120 * | |
121 * @var \Drupal\Core\Messenger\MessengerInterface | |
122 */ | |
123 protected $messenger; | |
116 | 124 |
117 /** | 125 /** |
118 * {@inheritdoc} | 126 * {@inheritdoc} |
119 */ | 127 */ |
120 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | 128 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
126 $container->get('entity.manager'), | 134 $container->get('entity.manager'), |
127 $container->get('module_handler'), | 135 $container->get('module_handler'), |
128 $container->get('config.factory')->get('search.settings'), | 136 $container->get('config.factory')->get('search.settings'), |
129 $container->get('language_manager'), | 137 $container->get('language_manager'), |
130 $container->get('renderer'), | 138 $container->get('renderer'), |
139 $container->get('messenger'), | |
131 $container->get('current_user') | 140 $container->get('current_user') |
132 ); | 141 ); |
133 } | 142 } |
134 | 143 |
135 /** | 144 /** |
151 * A config object for 'search.settings'. | 160 * A config object for 'search.settings'. |
152 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager | 161 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager |
153 * The language manager. | 162 * The language manager. |
154 * @param \Drupal\Core\Render\RendererInterface $renderer | 163 * @param \Drupal\Core\Render\RendererInterface $renderer |
155 * The renderer. | 164 * The renderer. |
165 * @param \Drupal\Core\Messenger\MessengerInterface $messenger | |
166 * The messenger. | |
156 * @param \Drupal\Core\Session\AccountInterface $account | 167 * @param \Drupal\Core\Session\AccountInterface $account |
157 * The $account object to use for checking for access to advanced search. | 168 * The $account object to use for checking for access to advanced search. |
158 */ | 169 */ |
159 public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, LanguageManagerInterface $language_manager, RendererInterface $renderer, AccountInterface $account = NULL) { | 170 public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, LanguageManagerInterface $language_manager, RendererInterface $renderer, MessengerInterface $messenger, AccountInterface $account = NULL) { |
160 $this->database = $database; | 171 $this->database = $database; |
161 $this->entityManager = $entity_manager; | 172 $this->entityManager = $entity_manager; |
162 $this->moduleHandler = $module_handler; | 173 $this->moduleHandler = $module_handler; |
163 $this->searchSettings = $search_settings; | 174 $this->searchSettings = $search_settings; |
164 $this->languageManager = $language_manager; | 175 $this->languageManager = $language_manager; |
165 $this->renderer = $renderer; | 176 $this->renderer = $renderer; |
177 $this->messenger = $messenger; | |
166 $this->account = $account; | 178 $this->account = $account; |
167 parent::__construct($configuration, $plugin_id, $plugin_definition); | 179 parent::__construct($configuration, $plugin_id, $plugin_definition); |
168 | 180 |
169 $this->addCacheTags(['node_list']); | 181 $this->addCacheTags(['node_list']); |
170 } | 182 } |
287 | 299 |
288 // Check query status and set messages if needed. | 300 // Check query status and set messages if needed. |
289 $status = $query->getStatus(); | 301 $status = $query->getStatus(); |
290 | 302 |
291 if ($status & SearchQuery::EXPRESSIONS_IGNORED) { | 303 if ($status & SearchQuery::EXPRESSIONS_IGNORED) { |
292 drupal_set_message($this->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', ['@count' => $this->searchSettings->get('and_or_limit')]), 'warning'); | 304 $this->messenger->addWarning($this->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', ['@count' => $this->searchSettings->get('and_or_limit')])); |
293 } | 305 } |
294 | 306 |
295 if ($status & SearchQuery::LOWER_CASE_OR) { | 307 if ($status & SearchQuery::LOWER_CASE_OR) { |
296 drupal_set_message($this->t('Search for either of the two terms with uppercase <strong>OR</strong>. For example, <strong>cats OR dogs</strong>.'), 'warning'); | 308 $this->messenger->addWarning($this->t('Search for either of the two terms with uppercase <strong>OR</strong>. For example, <strong>cats OR dogs</strong>.')); |
297 } | 309 } |
298 | 310 |
299 if ($status & SearchQuery::NO_POSITIVE_KEYWORDS) { | 311 if ($status & SearchQuery::NO_POSITIVE_KEYWORDS) { |
300 drupal_set_message($this->formatPlural($this->searchSettings->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'), 'warning'); | 312 $this->messenger->addWarning($this->formatPlural($this->searchSettings->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.')); |
301 } | 313 } |
302 | 314 |
303 return $find; | 315 return $find; |
304 } | 316 } |
305 | 317 |
473 // Add the title to text so it is searchable. | 485 // Add the title to text so it is searchable. |
474 $build['search_title'] = [ | 486 $build['search_title'] = [ |
475 '#prefix' => '<h1>', | 487 '#prefix' => '<h1>', |
476 '#plain_text' => $node->label(), | 488 '#plain_text' => $node->label(), |
477 '#suffix' => '</h1>', | 489 '#suffix' => '</h1>', |
478 '#weight' => -1000 | 490 '#weight' => -1000, |
479 ]; | 491 ]; |
480 $text = $this->renderer->renderPlain($build); | 492 $text = $this->renderer->renderPlain($build); |
481 | 493 |
482 // Fetch extra data normally not visible. | 494 // Fetch extra data normally not visible. |
483 $extra = $this->moduleHandler->invokeAll('node_update_index', [$node]); | 495 $extra = $this->moduleHandler->invokeAll('node_update_index', [$node]); |
779 '#type' => 'details', | 791 '#type' => 'details', |
780 '#title' => t('Content ranking'), | 792 '#title' => t('Content ranking'), |
781 '#open' => TRUE, | 793 '#open' => TRUE, |
782 ]; | 794 ]; |
783 $form['content_ranking']['info'] = [ | 795 $form['content_ranking']['info'] = [ |
784 '#markup' => '<p><em>' . $this->t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em></p>' | 796 '#markup' => '<p><em>' . $this->t('Influence is a numeric multiplier used in ordering search results. A higher number means the corresponding factor has more influence on search results; zero means the factor is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em></p>', |
785 ]; | 797 ]; |
786 // Prepare table. | 798 // Prepare table. |
787 $header = [$this->t('Factor'), $this->t('Influence')]; | 799 $header = [$this->t('Factor'), $this->t('Influence')]; |
788 $form['content_ranking']['rankings'] = [ | 800 $form['content_ranking']['rankings'] = [ |
789 '#type' => 'table', | 801 '#type' => 'table', |