search_exclude_nid.module in Search exclude nid 8
File
search_exclude_nid.module
View source
<?php
use Drupal\Core\Routing\RouteMatchInterface;
function search_exclude_nid_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.search_exclude_nid':
return t('
<h2>Lorem ipsum generator for Drupal.</h2>
<h3>Instructions</h3>
<p>Lorem ipsum dolor sit amet... <strong>Just kidding!</strong></p>
<p>Unpack in the <em>modules</em> folder (currently in the root of your Drupal 8 installation) and enable in <strong>/admin/modules</strong>.</p>
<p>Then, visit <strong>/admin/config/development/loremipsum</strong> and enter your own set of phrases to build random-generated text (or go with the default Lorem ipsum).</p>
<p>Last, visit <strong>www.example.com/loremipsum/generate/P/S</strong> where:</p>
<ul>
<li><em>P</em> is the number of <em>paragraphs</em></li>
<li><em>S</em> is the maximum number of <em>sentences</em></li>
</ul>
<p>There is also a generator block in which you can choose how many paragraphs and
phrases and it\'ll do the rest.</p>
<p>If you need, there\'s also a specific <em>generate lorem ipsum</em> permission.</p>
<h3>Attention</h3>
<p>Most bugs have been ironed out, holes covered, features added. But this module is a work in progress. Please report bugs and suggestions, ok?</p>
');
}
}
function search_exclude_nid_query_alter(Drupal\Core\Database\Query\AlterableInterface $query) {
if ($query
->hasTag('node_access') && $query
->hasTag('pager')) {
$tables = $query
->getTables();
foreach ($tables as $table) {
if ($table['table'] == 'search_index') {
$config = \Drupal::config('search_exclude_nid.settings');
$excluded_nids = $config
->get('excluded_nids');
if (count($excluded_nids)) {
$query
->condition('n.nid', $excluded_nids, 'NOT IN');
}
}
}
}
}