Commit 7209038e authored by adci_contributor's avatar adci_contributor
Browse files

Issue #3106019 by antongp: Drupal 9 compatibility

parent b567e007
......@@ -61,6 +61,7 @@
### Fixed
- [#3102734] by Corn696: View filter by keywords not possible, throws an error on view save
- [#3106019] by antongp: Drupal 9 compatibility
- [#3080686] by ablum: Contributor form does not save, thinks last name field is always null
- [#3013698] by antongp: Contributor full name pattern setting misses some of available name parts in description
- [#3066411] by antongp: There is no easy way to access Import and Export pages without Admin Toolbar module
......@@ -698,3 +699,4 @@ Add description to reference types, prefill it with sensible defaults. On refere
[#3080686]: https://www.drupal.org/node/3080686
[#3100514]: https://www.drupal.org/node/3100514
[#3102734]: https://www.drupal.org/node/3102734
[#3106019]: https://www.drupal.org/node/3106019
......@@ -2,6 +2,7 @@ name: Bibliography & Citation
type: module
description: Basic API for working with bibliographic data
core: 8.x
core_version_requirement: ^8 || ^9
package: Bibliography & Citation
configure: bibcite.settings
dependencies:
......
......@@ -2,6 +2,7 @@ name: 'Bibliography & Citation - BibTeX'
type: module
description: BibTeX encode and decode format
core: 8.x
core_version_requirement: ^8 || ^9
package: 'Bibliography & Citation - Formats'
dependencies:
- bibcite:bibcite
......
......@@ -7,7 +7,7 @@ services:
class: Drupal\bibcite_bibtex\Normalizer\BibtexReferenceNormalizer
tags:
- { name: normalizer, priority: 5 }
arguments: ['@entity.manager', '@config.factory']
arguments: ['@entity_type.manager', '@config.factory']
calls:
- [setFormat, ['bibtex']]
properties:
......
......@@ -2,6 +2,7 @@ name: 'Bibliography & Citation - Endnote'
type: module
description: Endnote encode and decode format
core: '8.x'
core_version_requirement: ^8 || ^9
package: 'Bibliography & Citation - Formats'
dependencies:
- bibcite:bibcite
......
......@@ -15,7 +15,7 @@ services:
class: Drupal\bibcite_endnote\Normalizer\EndnoteReferenceNormalizer
tags:
- { name: normalizer, priority: 5 }
arguments: ['@entity.manager', '@config.factory']
arguments: ['@entity_type.manager', '@config.factory']
calls:
- [setFormat, [['endnote7','endnote8','tagged']]]
properties:
......
......@@ -3,6 +3,7 @@ type: module
description: Storage for your bibliographic data.
package: Bibliography & Citation
core: 8.x
core_version_requirement: ^8 || ^9
configure: bibcite_entity.reference.settings
dependencies:
- bibcite:bibcite
......
......@@ -8,7 +8,6 @@
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter;
use Drupal\Core\Field\BaseFieldDefinition;
use Symfony\Component\Yaml\Yaml;
......@@ -201,7 +200,7 @@ function bibcite_entity_update_8006() {
else {
// If table view mode.
$config_list = $config_factory->listAll('core.entity_view_display.bibcite_reference');
$default_config_list = preg_grep('^.*default$', $config_list);
$default_config_list = preg_grep('/^.*default$/', $config_list);
foreach ($default_config_list as $default_config_name) {
$table_config_name = str_replace('default', 'table', $default_config_list);
$default_config = $config_factory->getEditable($default_config_name);
......@@ -226,7 +225,7 @@ function bibcite_entity_update_8006() {
}
// Write config for all not exist table view modes.
$table_config_list = preg_grep('^.*table$', $config_list);
$table_config_list = preg_grep('/^.*table$/', $config_list);
foreach ($table_config_list as $table_config_name) {
$table_config = $config_factory->getEditable($table_config_name);
if ($table_config->isNew()) {
......@@ -462,7 +461,7 @@ function bibcite_entity_update_8013() {
$definition_update_manager->updateEntityType($entity_type);
// Add the status field.
$status = Drupal\Core\Field\BaseFieldDefinition::create('boolean')
$status = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating the published state.'))
->setRevisionable(TRUE)
......@@ -472,20 +471,20 @@ function bibcite_entity_update_8013() {
$definition_update_manager->installFieldStorageDefinition('status', $entity_type_id, $entity_type_id, $status);
// Add the revision metadata fields.
$revision_created = Drupal\Core\Field\BaseFieldDefinition::create('created')
$revision_created = BaseFieldDefinition::create('created')
->setLabel(t('Revision create time'))
->setDescription(t('The time that the current revision was created.'))
->setRevisionable(TRUE);
$definition_update_manager->installFieldStorageDefinition('revision_created', $entity_type_id, $entity_type_id, $revision_created);
$revision_user = Drupal\Core\Field\BaseFieldDefinition::create('entity_reference')
$revision_user = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision user'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setRevisionable(TRUE);
$definition_update_manager->installFieldStorageDefinition('revision_user', $entity_type_id, $entity_type_id, $revision_user);
$revision_log_message = Drupal\Core\Field\BaseFieldDefinition::create('string_long')
$revision_log_message = BaseFieldDefinition::create('string_long')
->setLabel(t('Revision log message'))
->setDescription(t('Briefly describe the changes you have made.'))
->setRevisionable(TRUE)
......@@ -505,18 +504,15 @@ function bibcite_entity_update_8013() {
*/
function bibcite_entity_update_8014(&$sandbox) {
$database = \Drupal::database();
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$schema_converter = new SqlContentEntityStorageSchemaConverter(
'bibcite_reference',
\Drupal::entityTypeManager(),
\Drupal::entityDefinitionUpdateManager(),
\Drupal::service('entity.last_installed_schema.repository'),
\Drupal::keyValue('entity.storage_schema.sql'),
$database
);
$schema_converter->convertToRevisionable($sandbox, [
// Mark various fields as revisionable.
/** @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('bibcite_reference');
$fields_to_update = [
'uid',
'langcode',
'title',
'created',
'changed',
......@@ -570,7 +566,48 @@ function bibcite_entity_update_8014(&$sandbox) {
'bibcite_access_date',
'bibcite_refereed',
'bibcite_pmid',
]);
];
foreach ($fields_to_update as $field_name) {
$field_storage_definitions[$field_name]->setRevisionable(TRUE);
}
$field_storage_definitions['revision_id'] = BaseFieldDefinition::create('integer')
->setName('revision_id')
->setTargetEntityTypeId('bibcite_reference')
->setTargetBundle(NULL)
->setLabel(t('Revision ID'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$field_storage_definitions['revision_default'] = BaseFieldDefinition::create('boolean')
->setName('revision_default')
->setTargetEntityTypeId('bibcite_reference')
->setTargetBundle(NULL)
->setLabel(t('Default revision'))
->setDescription(t('A flag indicating whether this was a default revision when it was saved.'))
->setStorageRequired(TRUE)
->setInternal(TRUE)
->setTranslatable(FALSE)
->setRevisionable(TRUE);
$entity_type = $definition_update_manager->getEntityType('bibcite_reference');
$entity_keys = $entity_type->getKeys();
$entity_keys['revision'] = 'revision_id';
$entity_type->set('entity_keys', $entity_keys);
$revision_metadata_keys = [
'revision_default' => 'revision_default',
'revision_user' => 'revision_user',
'revision_created' => 'revision_created',
'revision_log_message' => 'revision_log_message',
];
$entity_type->set('revision_metadata_keys', $revision_metadata_keys);
$entity_type->set('revision_table', 'bibcite_reference_revision');
$definition_update_manager->updateFieldableEntityType(
$entity_type,
$field_storage_definitions,
$sandbox
);
}
/**
......
......@@ -8,17 +8,17 @@ services:
class: Drupal\bibcite_entity\Normalizer\ContributorNormalizer
tags:
- { name: normalizer, priority: 5 }
arguments: ['@entity.manager']
arguments: ['@entity_type.manager']
bibcite_entity.normalizer.keyword:
class: Drupal\bibcite_entity\Normalizer\KeywordNormalizer
tags:
- { name: normalizer, priority: 5 }
arguments: ['@entity.manager']
arguments: ['@entity_type.manager']
bibcite_entity.normalizer.reference:
class: Drupal\bibcite_entity\Normalizer\CslReferenceNormalizer
tags:
- { name: normalizer, priority: 5 }
arguments: ['@entity.manager', '@config.factory']
arguments: ['@entity_type.manager', '@config.factory']
calls:
- [setFormat, ['csl']]
properties:
......@@ -27,7 +27,7 @@ services:
keywordKey: 'keywords'
bibcite.ui_override_provider:
class: Drupal\bibcite_entity\UIOverrideProvider
arguments: ['@entity.manager', '@config.factory']
arguments: ['@entity_type.manager', '@config.factory']
plugin.manager.bibcite_link:
class: Drupal\bibcite_entity\Plugin\BibciteLinkPluginManager
parent: default_plugin_manager
......@@ -38,10 +38,10 @@ services:
arguments: ['@config.factory']
bibcite_entity.contributor_properties_service:
class: Drupal\bibcite_entity\ContributorPropertiesService
arguments: ['@entity.manager']
arguments: ['@entity_type.manager']
reference_entity.form_builder:
class: Drupal\bibcite_entity\ReferenceEntityFormBuilder
arguments: ['@entity.manager', '@reference.form_builder']
arguments: ['@entity_type.manager', '@reference.form_builder']
reference.form_builder:
class: Drupal\bibcite_entity\ReferenceFormBuilder
arguments: ['@form_validator', '@form_submitter', '@form_cache', '@module_handler', '@event_dispatcher', '@request_stack', '@class_resolver', '@element_info', '@theme.manager', '@?csrf_token']
......@@ -22,7 +22,9 @@ class ContributorViewsData extends EntityViewsData {
'numeric' => TRUE,
];
$entity_type = $this->entityManager->getDefinition('bibcite_reference');
// @todo Use $this->entityTypeManager only, once Drupal 8.9.0 is released.
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_type = $entity_manager->getDefinition('bibcite_reference');
$data[$this->entityType->getBaseTable()] += [
'name' => [
......
......@@ -21,7 +21,9 @@ class KeywordViewsData extends EntityViewsData {
'numeric' => TRUE,
];
$entity_type = $this->entityManager->getDefinition('bibcite_reference');
// @todo Use $this->entityTypeManager only, once Drupal 8.9.0 is released.
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_type = $entity_manager->getDefinition('bibcite_reference');
$data[$this->entityType->getBaseTable()] += [
'reverse__' . $entity_type->id() . '__' . $this->entityType->id() => [
......
......@@ -22,8 +22,7 @@ class ContributorNormalizer extends EntityNormalizer {
public function denormalize($data, $class, $format = NULL, array $context = []) {
/** @var \Drupal\bibcite_entity\Entity\ContributorInterface $entity */
$entity = parent::denormalize($data, $class, $format, $context);
// @todo Use $this->entityTypeManager only, once Drupal 8.8.0 is released.
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_manager = $this->getEntityTypeManager();
if (!empty($context['contributor_deduplication'])) {
$storage = $entity_manager->getStorage('bibcite_contributor');
......
......@@ -21,8 +21,7 @@ class KeywordNormalizer extends EntityNormalizer {
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
$entity = parent::denormalize($data, $class, $format, $context);
// @todo Use $this->entityTypeManager only, once Drupal 8.8.0 is released.
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_manager = $this->getEntityTypeManager();
if (!empty($context['keyword_deduplication'])) {
$storage = $entity_manager->getStorage('bibcite_keyword');
......
......@@ -6,7 +6,7 @@ use Drupal\bibcite_entity\Entity\Contributor;
use Drupal\bibcite_entity\Entity\Keyword;
use Drupal\bibcite_entity\Entity\ReferenceInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Url;
use Drupal\serialization\Normalizer\EntityNormalizer;
......@@ -112,12 +112,12 @@ abstract class ReferenceNormalizerBase extends EntityNormalizer {
/**
* Construct new BibliographyNormalizer object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Config factory.
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory) {
public function __construct(EntityTypeManagerInterface $entity_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($entity_manager);
$this->configFactory = $config_factory;
......
......@@ -35,9 +35,11 @@ class KeywordSelection extends DefaultSelection {
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$target_type = $this->configuration['target_type'];
$handler_settings = $this->configuration['handler_settings'];
$entity_type = $this->entityManager->getDefinition($target_type);
// @todo Use $this->entityTypeManager only, once Drupal 8.9.0 is released.
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_type = $entity_manager->getDefinition($target_type);
$query = $this->entityManager->getStorage($target_type)->getQuery();
$query = $entity_manager->getStorage($target_type)->getQuery();
if (isset($match) && $label_key = $entity_type->getKey('label')) {
$query->condition($label_key, $match, $match_operator);
......
......@@ -15,11 +15,14 @@ class BibciteContributor extends IdArgumentBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = $container->get('entity_type.manager');
$storage = $entity_manager->getStorage('bibcite_contributor');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('bibcite_contributor')
$storage
);
}
......
......@@ -15,11 +15,14 @@ class BibciteKeyword extends IdArgumentBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = $container->get('entity_type.manager');
$storage = $entity_manager->getStorage('bibcite_keyword');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('bibcite_keyword')
$storage
);
}
......
......@@ -15,11 +15,14 @@ class BibciteReference extends IdArgumentBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = $container->get('entity_type.manager');
$storage = $entity_manager->getStorage('bibcite_reference');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('bibcite_reference')
$storage
);
}
......
......@@ -3,7 +3,8 @@
namespace Drupal\bibcite_entity;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Language\LanguageManagerInterface;
......@@ -33,8 +34,8 @@ class ReferenceViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
public function __construct(EntityTypeInterface $entity_type, NormalizerInterface $serializer, ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, Registry $theme_registry = NULL) {
parent::__construct($entity_type, $entity_manager, $language_manager, $theme_registry);
public function __construct(EntityTypeInterface $entity_type, NormalizerInterface $serializer, ConfigFactoryInterface $config_factory, EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, Registry $theme_registry = NULL, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
parent::__construct($entity_type, $entity_repository, $language_manager, $theme_registry, $entity_display_repository);
$this->serializer = $serializer;
$this->configFactory = $config_factory;
......@@ -44,13 +45,26 @@ class ReferenceViewBuilder extends EntityViewBuilder {
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
/** @var \Symfony\Component\Serializer\Normalizer\NormalizerInterface $serializer */
$serializer = $container->get('serializer');
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $container->get('config.factory');
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = $container->get('entity.repository');
/** @var \Drupal\Core\Language\LanguageManagerInterface $language_manager */
$language_manager = $container->get('language_manager');
/** @var \Drupal\Core\Theme\Registry $theme_registry */
$theme_registry = $container->get('theme.registry');
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository */
$entity_display_repository = $container->get('entity_display.repository');
return new static(
$entity_type,
$container->get('serializer'),
$container->get('config.factory'),
$container->get('entity.manager'),
$container->get('language_manager'),
$container->get('theme.registry')
$serializer,
$config_factory,
$entity_repository,
$language_manager,
$theme_registry,
$entity_display_repository
);
}
......
......@@ -86,7 +86,9 @@ class ReferenceViewsData extends EntityViewsData {
],
];
$entity_type = $this->entityManager->getDefinition('bibcite_keyword');
// @todo Use $this->entityTypeManager only, once Drupal 8.9.0 is released.
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_type = $entity_manager->getDefinition('bibcite_keyword');
$data['bibcite_reference__keywords']['keywords_target_id']['relationship'] = [
'base' => $this->getViewsTableForEntityType($entity_type),
'base field' => $entity_type->getKey('id'),
......@@ -162,7 +164,8 @@ class ReferenceViewsData extends EntityViewsData {
],
];
$entity_type = $this->entityManager->getDefinition('bibcite_contributor');
$entity_manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
$entity_type = $entity_manager->getDefinition('bibcite_contributor');
$data['bibcite_reference__author']['author_target_id']['relationship'] = [
'base' => $this->getViewsTableForEntityType($entity_type),
'base field' => $entity_type->getKey('id'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment