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

Commit

Permalink
Merge pull request #91 from ec-europa/drop-drupal-8.5.x-support
Browse files Browse the repository at this point in the history
Drop support for Drupal 8.5.x. Support PHP 7.3, Drupal 8.7.x, 8.8.x
  • Loading branch information
pfrenssen authored May 2, 2019
2 parents 43aa15c + ea61b27 commit 4930f2d
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 11 deletions.
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: php

php:
- 7.1
- 7.2
- '7.1'
- '7.2'
- '7.3'

sudo: required

Expand All @@ -19,13 +20,16 @@ env:
- SITE_DIR="$HOME/build/testing_site"
matrix:
- TEST=PHP_CodeSniffer
- TEST=8.5.x
- TEST=8.6.x
- TEST=8.7.x
- TEST=8.8.x

matrix:
fast_finish: true
exclude:
- php: 7.2
- php: '7.2'
env: TEST=PHP_CodeSniffer
- php: '7.3'
env: TEST=PHP_CodeSniffer

before_install:
Expand Down
94 changes: 94 additions & 0 deletions modules/rdf_taxonomy/rdf_taxonomy.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* 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().
*/
Expand All @@ -14,4 +20,92 @@ function rdf_taxonomy_install() {
$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');
foreach (['revision_created', 'revision_user', 'revision_log_message'] 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);
}

}
15 changes: 11 additions & 4 deletions modules/rdf_taxonomy/src/Entity/RdfTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ class RdfTerm extends Term {
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$base_fields = parent::baseFieldDefinitions($entity_type);
// Support also Drupal 8.5.x.
if (isset($base_fields['status'])) {
$base_fields['status']->setCustomStorage(TRUE);
}
$base_fields['status']->setCustomStorage(TRUE);

// Don't support taxonomy term revisions.
unset(
$base_fields['revision_default'],
$base_fields['revision_translation_affected'],
$base_fields['revision_created'],
$base_fields['revision_user'],
$base_fields['revision_log_message']
);

return $base_fields;
}

Expand Down
15 changes: 15 additions & 0 deletions modules/rdf_taxonomy/src/TermRdfStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Drupal\rdf_entity\Entity\RdfEntitySparqlStorage;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\TermStorageInterface;
use Drupal\taxonomy\VocabularyInterface;
use EasyRdf\Graph;

/**
Expand Down Expand Up @@ -416,6 +417,20 @@ public function getNodeTerms(array $nids, array $vocabs = [], $langcode = NULL)
return $terms;
}

/**
* {@inheritdoc}
*/
public function getVocabularyHierarchyType($vid) {
return VocabularyInterface::HIERARCHY_SINGLE;
}

/**
* {@inheritdoc}
*/
public function getTermIdsWithPendingRevisions() {
return [];
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions rdf_entity.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Includes installation functions for the rdf_entity module.
*/

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Serialization\Yaml;
use Drupal\rdf_entity\Entity\RdfEntityGraph;
use Drupal\rdf_entity\Entity\RdfEntityMapping;
Expand Down Expand Up @@ -93,3 +94,18 @@ function rdf_entity_update_8002() {
$entity_definition_update_manager->installEntityType($entity_type);
}
}

/**
* Install the 'rdf_entity' entity type definition changes.
*/
function rdf_entity_update_8003() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$graph_field_definition = BaseFieldDefinition::create('entity_reference')
->setName('graph')
->setLabel(t('The graph where the entity is stored.'))
->setTargetEntityTypeId('rdf_entity')
->setTargetBundle(NULL)
->setCustomStorage(TRUE)
->setSetting('target_type', 'rdf_entity_graph');
$definition_update_manager->installFieldStorageDefinition('graph', 'rdf_entity', 'rdf_entity', $graph_field_definition);
}
2 changes: 1 addition & 1 deletion rdf_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function rdf_entity_entity_base_field_info_alter(array &$fields, EntityTypeInter

$fields['graph'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('The graph where the entity is stored.'))
->setTargetEntityTypeId('rdf_entity')
->setTargetEntityTypeId($entity_type->id())
->setName('graph')
->setCustomStorage(TRUE)
->setSetting('target_type', 'rdf_entity_graph');
Expand Down
3 changes: 1 addition & 2 deletions src/Entity/RdfEntitySparqlStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
$container->get('sparql.graph_handler'),
$container->get('sparql.field_handler'),
$container->get('plugin.manager.rdf_entity.id'),
// We support also Drupal 8.5.x.
$container->has('entity.memory_cache') ? $container->get('entity.memory_cache') : NULL
$container->get('entity.memory_cache')
);
}

Expand Down

0 comments on commit 4930f2d

Please sign in to comment.