Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

TEMP COMMIT. #138

Draft
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion modules/rdf_taxonomy/config/schema/rdf_taxonomy.schema.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
taxonomy.vocabulary.*.third_party.rdf_taxonomy:
taxonomy.rdf_taxonomy_vocabulary.*.third_party.rdf_taxonomy:
type: mapping
label: 'RDF Taxonomy third party settings'
mapping:
Expand Down
1 change: 0 additions & 1 deletion modules/rdf_taxonomy/rdf_taxonomy.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ package: Custom
core_version_requirement: ^8 || ^9
dependencies:
- rdf_entity:rdf_entity
- drupal:taxonomy
109 changes: 0 additions & 109 deletions modules/rdf_taxonomy/rdf_taxonomy.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,112 +5,3 @@
* Install rdf taxonomy.
*/

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rdf_taxonomy\Entity\RdfTerm;
use Drupal\rdf_taxonomy\RdfTaxonomyTermListBuilder;
use Drupal\rdf_taxonomy\TermRdfStorage;

/**
* Implements hook_install().
*/
function rdf_taxonomy_install() {
// Don't build a node - term index.
// When this should be needed, look into altering the schema.
$config = \Drupal::service('config.factory')->getEditable('taxonomy.settings');
$config->set('maintain_index_table', 0);
$config->save();

// Remove revision fields created by taxonomy.module.
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
/** @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $last_installed_schema_repository */
$last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');

$field_storage_definitions = $last_installed_schema_repository->getLastInstalledFieldStorageDefinitions('taxonomy_term');
$revision_fields = [
'revision_created',
'revision_user',
'revision_log_message',
];
foreach ($revision_fields as $field_name) {
// This check is just to ensure Drupal 8.6.x compatibility as those fields
// were added in Drupal 8.7.x.
// @todo Drop Drupal 8.6.x support in #92.
// @see https://github.com/ec-europa/rdf_entity/issues/92
if (isset($field_storage_definitions[$field_name])) {
$definition_update_manager->uninstallFieldStorageDefinition($field_storage_definitions[$field_name]);
}
}

// Install the 'graph' field definition. The field is not installed when the
// module is enabled because the 'taxonomy_term' entity type definition is
// installed earlier, when the taxonomy.module is installed. Thus, we'll have
// need explicitly install the field to entity type field storage definition.
$graph_field_definition = BaseFieldDefinition::create('entity_reference')
->setName('graph')
->setLabel(t('The graph where the entity is stored.'))
->setTargetEntityTypeId('taxonomy_term')
->setTargetBundle(NULL)
->setCustomStorage(TRUE)
->setSetting('target_type', 'rdf_entity_graph');
$definition_update_manager->installFieldStorageDefinition('graph', 'taxonomy_term', 'rdf_taxonomy', $graph_field_definition);
}

/**
* Install the 'taxonomy_term' entity type definition changes.
*/
function rdf_taxonomy_update_8001() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();

// Install entity type alters.
$entity_type = $definition_update_manager->getEntityType('taxonomy_term')
->setClass(RdfTerm::class)
->setStorageClass(TermRdfStorage::class)
->setHandlerClass('views_data', NULL)
->setHandlerClass('list_builder', RdfTaxonomyTermListBuilder::class);
$definition_update_manager->updateEntityType($entity_type);

// Install missed fields definitions.
$definitions = [
'graph' => BaseFieldDefinition::create('entity_reference')
->setName('graph')
->setLabel(t('The graph where the entity is stored.'))
->setTargetEntityTypeId('taxonomy_term')
->setTargetBundle(NULL)
->setCustomStorage(TRUE)
->setSetting('target_type', 'rdf_entity_graph'),
'revision_id' => BaseFieldDefinition::create('integer')
->setName('revision_id')
->setTargetEntityTypeId('taxonomy_term')
->setTargetBundle(NULL)
->setLabel(new TranslatableMarkup('Revision ID'))
->setReadOnly(TRUE)
->setCustomStorage(TRUE)
->setSetting('unsigned', TRUE),
'revision_default' => BaseFieldDefinition::create('boolean')
->setName('revision_default')
->setTargetEntityTypeId('taxonomy_term')
->setTargetBundle(NULL)
->setLabel(new TranslatableMarkup('Default revision'))
->setDescription(new TranslatableMarkup('A flag indicating whether this was a default revision when it was saved.'))
->setStorageRequired(TRUE)
->setInternal(TRUE)
->setTranslatable(FALSE)
->setCustomStorage(TRUE)
->setRevisionable(TRUE),
'revision_translation_affected' => BaseFieldDefinition::create('boolean')
->setName('revision_translation_affected')
->setTargetEntityTypeId('taxonomy_term')
->setTargetBundle(NULL)
->setLabel(new TranslatableMarkup('Revision translation affected'))
->setDescription(new TranslatableMarkup('Indicates if the last edit of a translation belongs to current revision.'))
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setCustomStorage(TRUE)
->setTranslatable(TRUE),
];
foreach ($definitions as $field_name => $definition) {
$definition_update_manager->installFieldStorageDefinition($field_name, 'taxonomy_term', 'rdf_taxonomy', $definition);
}

}
11 changes: 11 additions & 0 deletions modules/rdf_taxonomy/rdf_taxonomy.links.action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
entity.rdf_taxonomy_vocabulary.add_form:
route_name: entity.rdf_taxonomy_vocabulary.add_form
title: 'Add RDF vocabulary'
appears_on:
- entity.rdf_taxonomy_vocabulary.collection

entity.rdf_taxonomy_term.add_form:
route_name: entity.rdf_taxonomy_term.add_form
title: 'Add RDF term'
appears_on:
- entity.rdf_taxonomy_vocabulary.overview_form
17 changes: 17 additions & 0 deletions modules/rdf_taxonomy/rdf_taxonomy.links.contextual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
entity.rdf_taxonomy_term.edit_form:
title: Edit
group: rdf_taxonomy_term
route_name: entity.rdf_taxonomy_term.edit_form
weight: 10

entity.rdf_taxonomy_term.delete_form:
title: Delete
group: rdf_taxonomy_term
route_name: entity.rdf_taxonomy_term.delete_form
weight: 20

entity.rdf_taxonomy_vocabulary.delete_form:
title: Delete
group: rdf_taxonomy_vocabulary
route_name: entity.rdf_taxonomy_vocabulary.delete_form
weight: 20
5 changes: 5 additions & 0 deletions modules/rdf_taxonomy/rdf_taxonomy.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entity.rdf_taxonomy_vocabulary.collection:
title: RDF taxonomy
parent: system.admin_structure
description: 'Manage tagging, categorization, and classification of your content.'
route_name: entity.rdf_taxonomy_vocabulary.collection
19 changes: 19 additions & 0 deletions modules/rdf_taxonomy/rdf_taxonomy.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
entity.rdf_taxonomy_term.canonical:
title: 'View'
route_name: entity.rdf_taxonomy_term.canonical
base_route: entity.rdf_taxonomy_term.canonical

entity.rdf_taxonomy_term.edit_form:
title: 'Edit'
route_name: entity.rdf_taxonomy_term.edit_form
base_route: entity.rdf_taxonomy_term.canonical

entity.rdf_taxonomy_vocabulary.overview_form:
title: 'List'
route_name: entity.rdf_taxonomy_vocabulary.overview_form
base_route: entity.rdf_taxonomy_vocabulary.overview_form

entity.rdf_taxonomy_vocabulary.edit_form:
title: 'Edit'
route_name: entity.rdf_taxonomy_vocabulary.edit_form
base_route: entity.rdf_taxonomy_vocabulary.overview_form
54 changes: 7 additions & 47 deletions modules/rdf_taxonomy/rdf_taxonomy.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,36 @@
*/

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\sparql_entity_storage\Entity\Query\Sparql\SparqlArg;
use Drupal\sparql_entity_storage\Entity\SparqlMapping;
use Drupal\rdf_taxonomy\Entity\RdfTerm;
use Drupal\rdf_taxonomy\RdfTaxonomyTermListBuilder;
use Drupal\rdf_taxonomy\TermRdfStorage;
use Drupal\sparql_entity_storage\UriEncoder;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\VocabularyInterface;

/**
* Implements hook_entity_type_alter().
*
* Set the controller class for vocabularies and terms to an alternate
* implementation of the Drupal\Core\Entity\EntityStorageInterface interface.
*/
function rdf_taxonomy_entity_type_alter(array &$entity_types) {
$entity_types['taxonomy_term']->setClass(RdfTerm::class);
$entity_types['taxonomy_term']->setStorageClass(TermRdfStorage::class);
$entity_types['taxonomy_term']->setHandlerClass('views_data', NULL);
$entity_types['taxonomy_term']->setHandlerClass('list_builder', RdfTaxonomyTermListBuilder::class);
}

/**
* Implements hook_entity_base_field_info_alter().
*/
function rdf_taxonomy_entity_base_field_info_alter(array &$fields, EntityTypeInterface $entity_type): void {
if ($entity_type->id() != 'taxonomy_term') {
return;
}

/** @var \Drupal\Core\Field\BaseFieldDefinition $original_tid */
$original_tid = $fields['tid'];

// Change the tid type to string (RDF uri).
$fields['tid'] = BaseFieldDefinition::create('string')
->setName($original_tid->getName())
->setTargetEntityTypeId($original_tid->getTargetEntityTypeId())
->setTargetBundle($original_tid->getTargetBundle())
->setLabel($original_tid->getLabel())
->setDescription($original_tid->getDescription())
->setProvider('rdf_taxonomy')
->setReadOnly($original_tid->isReadOnly());
}

/**
* Implements hook_ENTITY_TYPE_access().
*/
function rdf_taxonomy_taxonomy_vocabulary_access(VocabularyInterface $vocabulary, $operation, AccountInterface $account) {
function rdf_taxonomy_rdf_taxonomy_vocabulary_access(VocabularyInterface $vocabulary, $operation, AccountInterface $account) {
$locked = ($operation !== 'view') && $vocabulary->getThirdPartySetting('rdf_taxonomy', 'locked', TRUE);
return AccessResult::forbiddenIf($locked);
}

/**
* Implements hook_ENTITY_TYPE_access().
*/
function rdf_taxonomy_taxonomy_term_access(TermInterface $term, $operation, AccountInterface $account) {
function rdf_taxonomy_rdf_taxonomy_term_access(TermInterface $term, $operation, AccountInterface $account) {
$locked = ($operation !== 'view') && $term->vid->entity->getThirdPartySetting('rdf_taxonomy', 'locked', TRUE);
return AccessResult::forbiddenIf($locked);
}

/**
* Implements hook_ENTITY_TYPE_create_access().
*/
function rdf_taxonomy_taxonomy_term_create_access(AccountInterface $account, array $context, $entity_bundle) {
function rdf_taxonomy_rdf_taxonomy_term_create_access(AccountInterface $account, array $context, $entity_bundle) {
$vocabulary = Vocabulary::load($entity_bundle);
$locked = $vocabulary->getThirdPartySetting('rdf_taxonomy', 'locked', TRUE);
return AccessResult::forbiddenIf($locked);
Expand All @@ -84,11 +44,11 @@ function rdf_taxonomy_taxonomy_term_create_access(AccountInterface $account, arr
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function rdf_taxonomy_form_taxonomy_term_form_alter(&$form, FormStateInterface $form_state, $form_id) {
function rdf_taxonomy_form_rdf_taxonomy_term_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $form_state->getFormObject()->getEntity();

$sparql_mapping = SparqlMapping::loadByName('taxonomy_term', $term->bundle());
$sparql_mapping = SparqlMapping::loadByName('rdf_taxonomy_term', $term->bundle());
if (!$sparql_mapping->isMapped('weight')) {
// RDF terms with no weight mapping have 0 weight.
$form['relations']['weight'] = [
Expand Down Expand Up @@ -120,7 +80,7 @@ function rdf_taxonomy_form_taxonomy_term_form_alter(&$form, FormStateInterface $
*
* @see template_preprocess_taxonomy_term()
*/
function rdf_taxonomy_preprocess_taxonomy_term(&$variables) {
function rdf_taxonomy_preprocess_rdf_taxonomy_term(&$variables) {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $variables['term'];
$variables['page'] = $variables['view_mode'] == 'full' && rdf_taxonomy_term_is_page($term);
Expand All @@ -137,7 +97,7 @@ function rdf_taxonomy_preprocess_taxonomy_term(&$variables) {
* @see taxonomy_term_is_page()
*/
function rdf_taxonomy_term_is_page(Term $term) {
if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical' && $page_term_id = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) {
if (\Drupal::routeMatch()->getRouteName() == 'entity.rdf_taxonomy_term.canonical' && $page_term_id = \Drupal::routeMatch()->getRawParameter('rdf_taxonomy_term')) {
if (!SparqlArg::isValidResource($page_term_id)) {
$page_term_id = UriEncoder::decodeUrl($page_term_id);
}
Expand Down
39 changes: 39 additions & 0 deletions modules/rdf_taxonomy/rdf_taxonomy.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
entity.rdf_taxonomy_term.add_form:
path: '/admin/structure/rdf-taxonomy/manage/{rdf_taxonomy_vocabulary}/add'
defaults:
_controller: '\Drupal\rdf_taxonomy\Controller\RdfTaxonomyController::addForm'
_title: 'Add term'
requirements:
_entity_create_access: 'rdf_taxonomy_term:{rdf_taxonomy_vocabulary}'

entity.rdf_taxonomy_term.edit_form:
path: '/rdf-taxonomy/term/{rdf_taxonomy_term}/edit'
defaults:
_entity_form: 'rdf_taxonomy_term.default'
_title: 'Edit term'
options:
_admin_route: TRUE
requirements:
_entity_access: 'rdf_taxonomy_term.update'
taxonomy_term: \d+

entity.rdf_taxonomy_term.delete_form:
path: '/rdf-taxonomy/term/{rdf_taxonomy_term}/delete'
defaults:
_entity_form: 'rdf_taxonomy_term.delete'
_title: 'Delete term'
options:
_admin_route: TRUE
requirements:
_entity_access: 'rdf_taxonomy_term.delete'
taxonomy_term: \d+

entity.rdf_taxonomy_term.canonical:
path: '/rdf-taxonomy/term/{rdf_taxonomy_term}'
defaults:
_entity_view: 'rdf_taxonomy_term.full'
_title: 'Taxonomy term'
_title_callback: '\Drupal\rdf_taxonomy\Controller\RdfTaxonomyController::termTitle'
requirements:
_entity_access: 'rdf_taxonomy_term.view'
taxonomy_term: \d+
10 changes: 0 additions & 10 deletions modules/rdf_taxonomy/rdf_taxonomy.services.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
services:
rdf_taxonomy.subscriber:
class: \Drupal\rdf_taxonomy\Routing\RouteSubscriber
arguments: ['@entity_type.manager']
tags:
- { name: event_subscriber }

rdf_taxonomy.overrider:
class: \Drupal\rdf_taxonomy\RdfTaxonomyConfigOverrides
tags:
- {name: config.factory.override, priority: 5}
rdf_taxonomy.outbound_value.term_parent.subscriber:
class: Drupal\rdf_taxonomy\EventSubscriber\OutboundTermParentSubscriber
tags:
Expand Down
30 changes: 30 additions & 0 deletions modules/rdf_taxonomy/src/Controller/RdfTaxonomyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Drupal\rdf_taxonomy\Controller;

use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\Controller\TaxonomyController;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\VocabularyInterface;

/**
* Provides route responses for rdf_taxonomy.module.
*/
class RdfTaxonomyController extends TaxonomyController {

/**
* Returns a form to add a new term to a vocabulary.
*
* @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
* The RDF vocabulary this term will be added to.
*
* @return array
* The RDF taxonomy term add form.
*/
public function addForm(VocabularyInterface $taxonomy_vocabulary) {
$term = $this->entityTypeManager()->getStorage('rdf_taxonomy_term')->create(['vid' => $taxonomy_vocabulary->id()]);
return $this->entityFormBuilder()->getForm($term);
}

}
Loading