Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds / dds.module
Size: Mime:
<?php

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Implements hook_theme().
 */
function dds_theme($existing, $type, $theme, $path) {
    return [
        'dds_spinner' => [
            'variables' => [],
        ],
    ];
}

function dds_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id === 'search_block_form') {
    $form['actions']['submit']['#name'] = 'search';
  }
}

/**
 * Implements hook_page_attachments_alter().
 */
function dds_page_attachments_alter(array &$attachments) {
  $request = \Drupal::request();
  $path_info = strtolower($request->getPathInfo());

  $config = \Drupal::config('dds.nofollow_settings');
  $identical_paths = $config->get('identical_paths');
  $noindex = preg_split("/\r\n|\n|\r/", $config->get('noindex'));
  $nofollow = preg_split("/\r\n|\n|\r/", $config->get('nofollow'));
  $nofollow_noindex = preg_split("/\r\n|\n|\r/", $config->get('nofollow_noindex'));

  if ($identical_paths) {
    if (!empty($nofollow_noindex)) {
      if (in_array($path_info, $nofollow_noindex)) {
        $attachments['#attached']['html_head'][] = [
          [
            '#tag' => 'meta',
            '#attributes' => [
              'name' => 'robots',
              'content' => 'noindex',
            ],
          ],
          'user_admin_no_index'
        ];
        $attachments['#attached']['html_head'][] = [
          [
            '#tag' => 'meta',
            '#attributes' => [
              'name' => 'robots',
              'content' => 'nofollow',
            ],
          ],
          'user_admin_no_follow'
        ];
      }
    }
  } else {
    // Only add noindex if there are any paths defined.
    if (!empty($noindex)) {
      if (in_array($path_info, $noindex)) {
        $attachments['#attached']['html_head'][] = [
          [
            '#tag' => 'meta',
            '#attributes' => [
              'name' => 'robots',
              'content' => 'noindex',
            ],
          ],
          'user_admin_no_index'
        ];
      }
    }

    // Only add nofollow if there are any paths defined.
    if (!empty($nofollow)) {
      if (in_array($path_info, $nofollow)) {
        $attachments['#attached']['html_head'][] = [
          [
            '#tag' => 'meta',
            '#attributes' => [
              'name' => 'robots',
              'content' => 'nofollow',
            ],
          ],
          'user_admin_no_follow'
        ];
      }
    }
  }
}