From 7c381409365c28f8224c7d249e68c3ab453d3ada Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 16 Apr 2019 14:23:10 +0300 Subject: [PATCH 1/7] Drop support for Drupal 8.5.x. Support PHP 7.3, Drupal 8.7.x, 8.8.x. --- .travis.yml | 12 ++++++++---- modules/rdf_taxonomy/src/Entity/RdfTerm.php | 5 +---- src/Entity/RdfEntitySparqlStorage.php | 3 +-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3fdf0a39..d38ca0f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: php php: - - 7.1 - - 7.2 + - '7.1' + - '7.2' + - '7.3' sudo: required @@ -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: diff --git a/modules/rdf_taxonomy/src/Entity/RdfTerm.php b/modules/rdf_taxonomy/src/Entity/RdfTerm.php index a08f993e..cc609cb2 100644 --- a/modules/rdf_taxonomy/src/Entity/RdfTerm.php +++ b/modules/rdf_taxonomy/src/Entity/RdfTerm.php @@ -15,10 +15,7 @@ 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); return $base_fields; } diff --git a/src/Entity/RdfEntitySparqlStorage.php b/src/Entity/RdfEntitySparqlStorage.php index c3d14b65..bc91225f 100644 --- a/src/Entity/RdfEntitySparqlStorage.php +++ b/src/Entity/RdfEntitySparqlStorage.php @@ -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') ); } From 134d45377a497b828d01780dc63eb9c44d0ddb1a Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 16 Apr 2019 14:41:47 +0300 Subject: [PATCH 2/7] Fix coding standards. --- src/Entity/Query/Sparql/Query.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Entity/Query/Sparql/Query.php b/src/Entity/Query/Sparql/Query.php index 32939fd9..c01c546f 100644 --- a/src/Entity/Query/Sparql/Query.php +++ b/src/Entity/Query/Sparql/Query.php @@ -168,10 +168,13 @@ public function graphs(array $graph_ids = NULL): SparqlQueryInterface { * @param string[]|null $graph_ids * (optional) An array of graphs ids to be passed into the query. * - * @deprecated Use the ::graphs() method instead. + * @deprecated in rdf_entity:8.x-1.x and will be removed from + * rdf_entity:8.x-1.0. Use the ::graphs() method instead. + * + * @see https://github.com/ec-europa/rdf_entity/issues */ public function setGraphType(array $graph_ids = NULL) { - @trigger_error('Drupal\rdf_entity\Entity\Query\Sparql\Query::setGraphType() is deprecated. Use the ::graphs() method instead.', E_USER_DEPRECATED); + @trigger_error('Drupal\rdf_entity\Entity\Query\Sparql\Query::setGraphType() is deprecated in rdf_entity:8.x-1.x. Use the \Drupal\rdf_entity\Entity\Query\Sparql\Query::graphs() method instead. See https://github.com/ec-europa/rdf_entity/issues', E_USER_DEPRECATED); $graph_ids = $graph_ids ?: [$this->graphHandler->getDefaultGraphId($this->getEntityTypeId())]; $this->graphs($graph_ids); } From 34a07917e80af53e71e81c6420598496efdd1eb4 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 16 Apr 2019 14:45:50 +0300 Subject: [PATCH 3/7] Add new method implementations in TermRdfStorage. --- modules/rdf_taxonomy/src/TermRdfStorage.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/rdf_taxonomy/src/TermRdfStorage.php b/modules/rdf_taxonomy/src/TermRdfStorage.php index 5e6bf674..9a1d9eee 100644 --- a/modules/rdf_taxonomy/src/TermRdfStorage.php +++ b/modules/rdf_taxonomy/src/TermRdfStorage.php @@ -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; /** @@ -408,6 +409,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} */ From 47e868d5e5d80fe75ea72c0681c4c769a9553bc3 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 16 Apr 2019 15:17:38 +0300 Subject: [PATCH 4/7] Remove deprecated setGraphType() method. --- src/Entity/Query/Sparql/Query.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Entity/Query/Sparql/Query.php b/src/Entity/Query/Sparql/Query.php index c01c546f..d594fca6 100644 --- a/src/Entity/Query/Sparql/Query.php +++ b/src/Entity/Query/Sparql/Query.php @@ -162,23 +162,6 @@ public function graphs(array $graph_ids = NULL): SparqlQueryInterface { return $this; } - /** - * Sets the graph types for the query. - * - * @param string[]|null $graph_ids - * (optional) An array of graphs ids to be passed into the query. - * - * @deprecated in rdf_entity:8.x-1.x and will be removed from - * rdf_entity:8.x-1.0. Use the ::graphs() method instead. - * - * @see https://github.com/ec-europa/rdf_entity/issues - */ - public function setGraphType(array $graph_ids = NULL) { - @trigger_error('Drupal\rdf_entity\Entity\Query\Sparql\Query::setGraphType() is deprecated in rdf_entity:8.x-1.x. Use the \Drupal\rdf_entity\Entity\Query\Sparql\Query::graphs() method instead. See https://github.com/ec-europa/rdf_entity/issues', E_USER_DEPRECATED); - $graph_ids = $graph_ids ?: [$this->graphHandler->getDefaultGraphId($this->getEntityTypeId())]; - $this->graphs($graph_ids); - } - /** * Initialize the query. * From 06b743b9e95c663be82dc85ac467e4c2c0eff09a Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 16 Apr 2019 22:42:34 +0300 Subject: [PATCH 5/7] Install the 'taxonomy_term' entity type definition updates. --- modules/rdf_taxonomy/rdf_taxonomy.install | 94 +++++++++++++++++++++ modules/rdf_taxonomy/src/Entity/RdfTerm.php | 10 +++ rdf_entity.module | 2 +- 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/modules/rdf_taxonomy/rdf_taxonomy.install b/modules/rdf_taxonomy/rdf_taxonomy.install index 54769503..5370fed3 100644 --- a/modules/rdf_taxonomy/rdf_taxonomy.install +++ b/modules/rdf_taxonomy/rdf_taxonomy.install @@ -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(). */ @@ -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('rdf_entity') + ->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('rdf_entity') + ->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); + } + } diff --git a/modules/rdf_taxonomy/src/Entity/RdfTerm.php b/modules/rdf_taxonomy/src/Entity/RdfTerm.php index cc609cb2..4daa4cbb 100644 --- a/modules/rdf_taxonomy/src/Entity/RdfTerm.php +++ b/modules/rdf_taxonomy/src/Entity/RdfTerm.php @@ -16,6 +16,16 @@ class RdfTerm extends Term { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $base_fields = parent::baseFieldDefinitions($entity_type); $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; } diff --git a/rdf_entity.module b/rdf_entity.module index 19fb0438..56218eda 100755 --- a/rdf_entity.module +++ b/rdf_entity.module @@ -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'); From 477d6ed8f369c222fdd22d75af3a6a2b746bfdfa Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Wed, 17 Apr 2019 10:03:16 +0300 Subject: [PATCH 6/7] Install the 'rdf_entity' entity type definition updates. --- rdf_entity.install | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rdf_entity.install b/rdf_entity.install index fc5debac..22615bfd 100644 --- a/rdf_entity.install +++ b/rdf_entity.install @@ -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; @@ -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); +} From ea61b27528febbe12b339d1dae07cbbbbaf377c1 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Thu, 2 May 2019 11:55:38 +0300 Subject: [PATCH 7/7] Fix 'graph' field target entity type ID. --- modules/rdf_taxonomy/rdf_taxonomy.install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/rdf_taxonomy/rdf_taxonomy.install b/modules/rdf_taxonomy/rdf_taxonomy.install index 5370fed3..8b5e75da 100644 --- a/modules/rdf_taxonomy/rdf_taxonomy.install +++ b/modules/rdf_taxonomy/rdf_taxonomy.install @@ -44,7 +44,7 @@ function rdf_taxonomy_install() { $graph_field_definition = BaseFieldDefinition::create('entity_reference') ->setName('graph') ->setLabel(t('The graph where the entity is stored.')) - ->setTargetEntityTypeId('rdf_entity') + ->setTargetEntityTypeId('taxonomy_term') ->setTargetBundle(NULL) ->setCustomStorage(TRUE) ->setSetting('target_type', 'rdf_entity_graph'); @@ -70,7 +70,7 @@ function rdf_taxonomy_update_8001() { 'graph' => BaseFieldDefinition::create('entity_reference') ->setName('graph') ->setLabel(t('The graph where the entity is stored.')) - ->setTargetEntityTypeId('rdf_entity') + ->setTargetEntityTypeId('taxonomy_term') ->setTargetBundle(NULL) ->setCustomStorage(TRUE) ->setSetting('target_type', 'rdf_entity_graph'),