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/rdf_taxonomy.install b/modules/rdf_taxonomy/rdf_taxonomy.install index 54769503..8b5e75da 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('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); + } + } diff --git a/modules/rdf_taxonomy/src/Entity/RdfTerm.php b/modules/rdf_taxonomy/src/Entity/RdfTerm.php index a08f993e..4daa4cbb 100644 --- a/modules/rdf_taxonomy/src/Entity/RdfTerm.php +++ b/modules/rdf_taxonomy/src/Entity/RdfTerm.php @@ -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; } diff --git a/modules/rdf_taxonomy/src/TermRdfStorage.php b/modules/rdf_taxonomy/src/TermRdfStorage.php index 334abfd2..082aee92 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; /** @@ -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} */ 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); +} 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'); 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') ); }