Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 61 additions & 50 deletions purl.install
Original file line number Diff line number Diff line change
@@ -1,58 +1,69 @@
<?php

function purl_schema()
{
$schema = array();
/**
* Implements hook_schema().
*/
function purl_schema() {
// Flush all caches to prevent the 'Plugin not found'-exception on install.
drupal_flush_all_caches();

$schema['purl_providers_settings'] = array(
'fields' => array(
'provider' => array(
'type' => 'varchar',
'length' => 150,
'not null' => true,
),
'method' => array(
'type' => 'varchar',
'length' => 255,
'not null' => true,
),
'settings' => array(
'type' => 'text',
'not null' => true,
'mysql_type' => 'mediumtext',
),
'rebuild' => array(
'type' => 'int',
//'size' => 'tinyint',
'default' => 0,
),
),
'primary key' => array('provider'),
'description' => 'PURL provider settings',
$schema['purl_providers_settings'] = array(
'fields' => array(
'provider' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'method' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'settings' => array(
'description' => '',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
),
'rebuild' => array(
'description' => '',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(array('provider', 191)),
'description' => 'PURL provider settings',
);

$schema['purl_modifiers'] = array(
'fields' => array(
'provider' => array(
'type' => 'varchar',
'length' => 150,
'not null' => true,
),
'modifier' => array(
'type' => 'varchar',
'length' => 150,
'not null' => true,
),
'value' => array(
'type' => 'text',
'not null' => true,
'mysql_type' => 'mediumtext',
),
),
'primary key' => array('provider', 'modifier'),
'description' => 'Index of PURL modifiers',
);
$schema['purl_modifiers'] = array(
'fields' => array(
'provider' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'modifier' => array(
'description' => '',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'value' => array(
'description' => '',
'type' => 'text',
'not null' => TRUE,
'mysql_type' => 'mediumtext',
),
),
'primary key' => array(array('provider', 191), array('modifier', 191)),
'description' => 'Index of PURL modifiers',
);

return $schema;
return $schema;
}

43 changes: 0 additions & 43 deletions purl.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,6 @@ use Drupal\purl\Entity\Provider;
use Drupal\node\NodeTypeInterface;
use Drupal\Core\Form;

function purl_entity_base_field_info(EntityTypeInterface $entity_type) {

if ($entity_type->id() !== 'menu_link_content') {
return;
}

$fields = [];

/* @todo Remove this; we don't need these extra fields anymore */

$fields['purl_provider'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('PURL provider'))
->setName('purl_provider')
->setRevisionable(false)
->setTranslatable(false)
->setDescription('PURL provider')
->setSettings([
'target_type' => 'purl_provider',
'default_value' => null,
]);

$fields['purl_modifier'] = BaseFieldDefinition::create('string')
->setLabel(t('PURL modifier'))
->setName('purl_modifier')
->setRevisionable(false)
->setDescription('PURL modififer')
->setSettings([
'default_value' => null,
'max_length' => 255,
]);

$fields['purl_strip_context'] = BaseFieldDefinition::create('boolean')
->setLabel(t('PURL strip context'))
->setName('purl_strip_context')
->setRevisionable(false)
->setDescription('PURL strip context')
->setSettings([
'default_value' => false,
]);

return $fields;
}

function purl_form_menu_edit_form_alter(&$form, $form_state) {
$providers = Provider::loadMultiple();

Expand Down
13 changes: 4 additions & 9 deletions purl.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:

purl.request_subscriber:
class: Drupal\purl\Event\RequestSubscriber
arguments:
arguments:
- '@purl.modifier_index'
- '@purl.matched_modifiers'
tags:
Expand All @@ -29,11 +29,6 @@ services:
tags:
- { name: event_subscriber }

purl.provider_storage:
class: Drupal\Core\Entity\EntityStorageInterface
factory: ['@entity.manager', getStorage]
arguments: ['purl_provider']

cache_context.purl:
class: Drupal\purl\Cache\Context\PurlCacheContext
tags:
Expand All @@ -42,14 +37,14 @@ services:

purl.rebuild_index:
class: Drupal\purl\Event\RebuildIndex
arguments:
arguments:
- '@purl.modifier_index'
tags:
- { name: event_subscriber }

purl.outbound_path_processor:
class: Drupal\purl\PathProcessor\PurlContextOutboundPathProcessor
arguments:
arguments:
- '@purl.matched_modifiers'
- '@purl.context_helper'
tags:
Expand Down Expand Up @@ -78,4 +73,4 @@ services:

purl.context_helper:
class: Drupal\purl\ContextHelper
arguments: ['@purl.provider_storage']
arguments: ['@entity_type.manager']
2 changes: 1 addition & 1 deletion src/Annotation/PurlMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct($values)
}

if (!isset($this->definition['stages'])) {
$this->definition['stage'] = [MethodInterface::STAGE_PROCESS_OUTBOUND];
$this->definition['stages'] = [MethodInterface::STAGE_PROCESS_OUTBOUND];
}
}
}
19 changes: 12 additions & 7 deletions src/ContextHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Drupal\purl;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\purl\Entity\Provider;
use Drupal\purl\Plugin\Purl\Method\MethodInterface;
Expand All @@ -12,13 +12,18 @@ class ContextHelper
{

/**
* @var EntityStorageInterface
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $storage;
protected $entityTypeManager;

public function __construct(EntityStorageInterface $storage)
/**
* ContextHelper constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
*/
public function __construct(EntityTypeManager $entity_type_manager)
{
$this->storage = $storage;
$this->entityTypeManager = $entity_type_manager;
}

/**
Expand Down Expand Up @@ -105,10 +110,10 @@ public function createContextsFromMap(array $map)
return [];
}

$providers = $this->storage->loadMultiple(array_keys($map));
$providers = $this->entityTypeManager->getStorage('purl_provider')->loadMultiple(array_keys($map));

return array_map(function (Provider $provider) use ($map) {
return new Context($map[$provider->id()], $provider->getMethodPlugin());
}, $providers);
}
}
}
14 changes: 5 additions & 9 deletions src/Controller/ModifiersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public function modifiers(Request $request)
{
$build = array();

$ids = \Drupal::entityQuery('purl_provider')
->execute();

$headers = array('provider', 'modifier', 'value');

$headers = array_map(function ($header) {
Expand All @@ -56,9 +53,9 @@ public function modifiers(Request $request)

$rows = array();

foreach ($this->modifierIndex->findModifiers() as $modifier) {
foreach ($this->modifierIndex->findAll() as $modifier) {

$provider = $modifier['provider'];
$provider = $modifier->getProvider();

if (!$provider) {
continue;
Expand All @@ -67,29 +64,28 @@ public function modifiers(Request $request)
$row = array();

$row[] = array(
'data' => $provider->getLabel()
'data' => $provider->getLabel(),
);

$row[] = array(
'data' => array(
'#type' => 'html_tag',
'#tag' => 'code',
'#value' => $modifier['modifier'],
'#value' => $modifier->getModifierKey(),
),
);

$row[] = array(
'data' => array(
'#type' => 'html_tag',
'#tag' => 'code',
'#value' => $this->stringify($modifier['value']),
'#value' => $this->stringify($modifier->getValue()),
),
);

$rows[] = $row;
}


$build['modifiers'] = array(
'#theme' => 'table',
'#header' => $headers,
Expand Down
2 changes: 2 additions & 0 deletions src/Event/RequestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function onRequest(GetResponseEvent $event, $eventName, EventDispatcherIn
{
$request = $event->getRequest();
$modifiers = $this->getModifiers();
$original_uri = $request->getRequestUri();

$matches = array();

Expand Down Expand Up @@ -104,6 +105,7 @@ public function onRequest(GetResponseEvent $event, $eventName, EventDispatcherIn
}

$request->attributes->set('purl.matched_modifiers', $matches);
$request->attributes->set('original_uri', $original_uri);
}

/**
Expand Down
Loading