You are here

purl.module in Persistent URL 8

Same filename and directory in other branches
  1. 6 purl.module
  2. 7 purl.module

File

purl.module
View source
<?php

function purl_rebuild() {
  $modifierIndex = \Drupal::service('purl.modifier_index');
  $modifierIndex
    ->deleteAll();
  $modifierIndex
    ->rebuild();
}
function purl_form_menu_edit_form_alter(&$form, $form_state) {

  // Edit menu as whole
  //
  $providerManager = \Drupal::getContainer()
    ->get('purl.plugin.provider_manager');
  $definitions = $providerManager
    ->findDefinitions();
  $active = [
    null => '-- None --',
  ];
  foreach ($definitions as $id => $def) {
    if (!$def['method']) {
      continue;
    }
    $active[$id] = $def['name'];
  }
  $form['purl'] = [
    '#tree' => true,
    '#type' => 'fieldset',
    '#title' => 'Persistent URLs',
    '#collapsible' => false,
    '#collapsed' => false,
  ];
  $form['purl']['purl_provider'] = array(
    '#type' => 'select',
    '#title' => 'PURL provider',
    '#value' => null,
    '#options' => $active,
  );
}
function purl_form_menu_link_content_menu_link_content_form_alter(&$form, $form_state) {

  // Edit menu item
}
function purl_form_alter(&$form, $form_state) {

  //kint($form);
}

/**
 * Implements hook_preprocess_html().
 */
function purl_preprocess_html(&$vars) {
  $init = \Drupal::requestStack();
  $request = $init
    ->getCurrentRequest();
  $modifiers = $request->attributes
    ->get('purl.matched_modifiers', []);
  foreach ($modifiers as $modifier) {
    foreach ($modifier as $key => $item) {
      if (!is_object($item)) {
        $vars['attributes']['class'][] = 'purl-' . $key . '-' . $item;
      }
    }
  }
}