Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #54 from openeuropa/OEL-77
Browse files Browse the repository at this point in the history
Drupal 9 compatibility fixes
  • Loading branch information
hernani authored Jul 5, 2021
2 parents b29e2ff + 582e3cd commit 88a9c1f
Show file tree
Hide file tree
Showing 22 changed files with 120 additions and 101 deletions.
1 change: 0 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,4 @@ matrix:
- lowest
- highest
PHP_VERSION:
- 7.2
- 7.3
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Entity Meta Relation

The Entity meta relation module allows to associate extra information stored in independent entities (meta entities) to content (host) entities. This avoids the need to store this information as a content entity field and pollute the content entity keeping metadata information that controls specific entity behaviour outside of its main storage.
The Entity meta relation module allows to associate extra information stored in independent entities (meta entities) to content (host) entities. This avoids the need to store this information as a content entity field and pollute the content entity keeping metadata information that controls specific entity behaviour outside of its main storage.
## Content Structure

* `EntityMeta` entities are regular content entities that can be fieldable and revisionable.
* `EntityMetaRelation` entities hold the relationship between content entities (such as nodes) and their `EntityMeta` entities. The relations are held directly to content entity revisions and `EntityMeta` revisions allowing to follow new revisions in both directions.
`EntityMeta` entities require a defined relation between themselves and content (host) entities. Moreover, each `EntityMeta` bundle is made applicable to each content entity bundle through configuration defined in 3rd party settings. The required configuration can be set automatically by using *EntityMetaRelationInstaller* service. An example of its usage can be seen in *entity_meta_example_install*.
`EntityMeta` entities require a defined relation between themselves and content (host) entities. Moreover, each `EntityMeta` bundle is made applicable to each content entity bundle through configuration defined in 3rd party settings. The required configuration can be set automatically by using *EntityMetaRelationInstaller* service. An example of its usage can be seen in *entity_meta_example_install*.
The `entity_meta_example` module contain several example plugins that are used for tests but can be used as references.

## Support for new content entities

Entity meta relations can be used with any content entity.
Entity meta relations can be used with any content entity.

However, the `emr_node` module already provides support for `Node` entities. It can be used to understand how to provide support for other content entities.
* A new `EntityMetaRelation` bundle should be created with at least two fields:
* A new `EntityMetaRelation` bundle should be created with at least two fields:
* one `EntityReferenceRevision` field that targets the (host) content entity revisions (see the `emr_node_revision` field as an example for relating to Node entities).
* one field that targets the `EntityMeta` revisions (see the `emr_meta_revision` field as an example for relating to the `EntityMeta` entities. The storage of this field could be reused).
* The host entity definition should be altered to include the following properties:
- `entity_meta_relation_bundle`: Should specify the `EntityMetaRelation` bundle you created above.
- `entity_meta_relation_content_field`: Should specify the field name that relates to the content (host) entity you created above.
- `entity_meta_relation_meta_field`: Should specify the field name that relates to the `EntityMeta` entities you created above.
- `emr_content_form`: In case the content (host) entity form should be used to include a form to manipulate the related `EntityMeta` entities, this should specify the form handler class to use for this.
- `emr_content_form`: In case the content (host) entity form should be used to include a form to manipulate the related `EntityMeta` entities, this should specify the form handler class to use for this.

Foe more information, check `emr_node_entity_type_alter` for an example how this is done for nodes:

The following is defined:

- The `EntityMetaRelation` bundle is `node_meta_relation`, and it has two fields:
- `emr_node_revision`: points to the `Node` entity revision
- `emr_node_revision`: points to the `Node` entity revision
- `emr_meta_revision`: points to the `EntityMeta` revision
- The handler class `NodeFormHandler` is defined to deal with content entity form changes.

Expand Down Expand Up @@ -89,7 +89,7 @@ $entity_meta->set('field_color', 'red');
// node is saved, the relations are created automatically.
$entity_meta_list->attach($entity_meta);
$node->save();
```
```
### Adding several EntityMeta entities to content entity
Expand Down Expand Up @@ -123,7 +123,7 @@ $entity_metas[] = $entity_meta;
// Set the array of entites meta entities as values.
$entity_meta_list->set($entity_metas);
$node->save();
```
```
### Using an EntityMetaWrapper
Expand Down Expand Up @@ -156,7 +156,7 @@ $node->save();
Please note that the `attach()` method won't do anything if there is no change
detected in the `EntityMeta` entity.
### Removing existing EntityMeta
### Removing existing EntityMeta

Existing `EntityMeta` entities can be removed from the revision through the `detach()` method.

Expand All @@ -180,6 +180,25 @@ composer install
A post command hook (`drupal:site-setup`) is triggered automatically after `composer install`.
It will make sure that the necessary symlinks are properly setup in the development site.
It will also perform token substitution in development configuration files such as `behat.yml.dist`.

This will also:
- Symlink the theme in `./build/modules/custom/entity_meta_relation` so that it's available for the test site
- Setup Drush and Drupal's settings using values from `./runner.yml.dist`.
- Setup PHPUnit and Behat configuration files using values from `./runner.yml.dist`

**Please note:** project files and directories are symlinked within the test site by using the
[OpenEuropa Task Runner's Drupal project symlink](https://github.com/openeuropa/task-runner-drupal-project-symlink)
command.

If you add a new file or directory in the root of the project, you need to re-run `drupal:site-setup` in order to make
sure they are correctly symlinked.

If you don't want to re-run a full site setup for that, you can simply run:

```
$ ./vendor/bin/run drupal:symlink-project
```

* Install test site by running:
Expand All @@ -191,10 +210,10 @@ The development site web root should be available in the `build` directory.
### Using Docker Compose
Alternatively, you can build a development site using [Docker](https://www.docker.com/get-docker) and
Alternatively, you can build a development site using [Docker](https://www.docker.com/get-docker) and
[Docker Compose](https://docs.docker.com/compose/) with the provided configuration.
Docker provides the necessary services and tools such as a web server and a database server to get the site running,
Docker provides the necessary services and tools such as a web server and a database server to get the site running,
regardless of your local host configuration.
#### Requirements:
Expand All @@ -206,7 +225,7 @@ regardless of your local host configuration.
By default, Docker Compose reads two files, a `docker-compose.yml` and an optional `docker-compose.override.yml` file.
By convention, the `docker-compose.yml` contains your base configuration and it's provided by default.
The override file, as its name implies, can contain configuration overrides for existing services or entirely new
The override file, as its name implies, can contain configuration overrides for existing services or entirely new
services.
If a service is defined in both files, Docker Compose merges the configurations.
Expand Down
2 changes: 1 addition & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default:
suites:
default:
paths:
- %paths.base%/tests/features
- "%paths.base%/tests/features"
contexts:
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\DrupalContext
Expand Down
31 changes: 11 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,22 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"drupal/core": "^8.7",
"drupal/inline_entity_form": "^1.0",
"php": ">=7.3",
"drupal/core": "^8.9 || ^9.1",
"drupal/entity_reference_revisions": "^1.6",
"php": ">=7.2"
"drupal/inline_entity_form": "^1.0"
},
"require-dev": {
"composer/installers": "~1.5",
"consolidation/robo": "~1.4",
"consolidation/annotated-command": "^2.8.2",
"drupal/core-composer-scaffold": "^8.8",
"drupal/config_devel": "~1.2",
"drupal/drupal-extension": "~4.0",
"drush/drush": "~9.0@stable",
"guzzlehttp/guzzle": "~6.3",
"openeuropa/code-review": "~1.5.0",
"openeuropa/drupal-core-require-dev": "^8.7",
"openeuropa/task-runner": "~1.0.0-beta5",
"phpunit/phpunit": "~6.0",
"symfony/browser-kit": "~3.0||~4.0"
"drupal/core-composer-scaffold": "^8.9 || ^9.1",
"drupal/config_devel": "^1.2",
"drupal/drupal-extension": "^4.0",
"drush/drush": "^10.3",
"openeuropa/code-review": "^1.6",
"openeuropa/drupal-core-require-dev": "^8.9 || ^9.1",
"openeuropa/task-runner-drupal-project-symlink": "^1.0",
"phpspec/prophecy-phpunit": "^1 || ^2"
},
"_readme": [
"We explicitly require consolidation/robo to allow lower 'composer update --prefer-lowest' to complete successfully.",
"We explicitly require consolidation/annotated-command to allow lower 'composer update --prefer-lowest' to complete successfully.",
"We explicitly require symfony/browser-kit to make phpunit tests pass for 'composer update --prefer-lowest'."
],
"scripts": {
"post-install-cmd": "./vendor/bin/run drupal:site-setup",
"post-update-cmd": "./vendor/bin/run drupal:site-setup"
Expand Down
2 changes: 1 addition & 1 deletion emr.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Relation
type: module
description: 'Provides an entity meta relation entity and associated behaviors for relations.'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_reference_revisions:entity_reference_revisions
2 changes: 1 addition & 1 deletion modules/emr_node/emr_node.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Relation Node
type: module
description: 'Configure entity meta relations for nodes.'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_meta_relation:emr
Expand Down
2 changes: 1 addition & 1 deletion modules/entity_meta_example/entity_meta_example.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Example
type: module
description: 'Defines an example meta entity to be related with nodes'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_meta_relation:emr_node
Expand Down
5 changes: 4 additions & 1 deletion modules/entity_meta_example/entity_meta_example.install
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ declare(strict_types = 1);
/**
* Implements hook_install().
*/
function entity_meta_example_install() {
function entity_meta_example_install($is_syncing) {
if ($is_syncing) {
return;
}
/** @var \Drupal\emr\EntityMetaRelationInstaller $installer */
$installer = \Drupal::service('emr.installer');
$installer->installEntityMetaTypeOnContentEntityType('visual', 'node', ['entity_meta_example_ct']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Audio
type: module
description: 'Defines an example meta entity for audio information'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_meta_relation:emr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Force
type: module
description: 'Defines an example meta entity for force information'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_meta_relation:emr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Speed
type: module
description: 'Defines an example meta entity for speed information'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_meta_relation:emr_node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Entity Meta Visual
type: module
description: 'Defines an example meta entity for visual information'
package: Entity Meta Relation
core: 8.x
core_version_requirement: ^8.9 || ^9.1

dependencies:
- entity_meta_relation:emr_node
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="${drupal.root}/core/tests/bootstrap.php" backupGlobals="true" colors="true" >
<phpunit bootstrap="${drupal.root}/core/tests/bootstrap.php" backupGlobals="true" colors="true" cacheResult="false">
<php>
<ini name="error_reporting" value="32767"/>
<ini name="memory_limit" value="-1"/>
Expand All @@ -8,7 +8,7 @@
<env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/>
</php>
<testsuites>
<testsuite>
<testsuite name="Entity meta relation tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ drupal:

commands:
drupal:site-setup:
- { task: "symlink", from: "../../..", to: "${drupal.root}/modules/custom/emr" }
- { task: "run", command: "drupal:symlink-project" }
- { task: "run", command: "drupal:drush-setup" }
- { task: "run", command: "drupal:settings-setup" }
- { task: "run", command: "setup:phpunit" }
Expand Down
1 change: 1 addition & 0 deletions src/Entity/EntityMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* "status" = "status"
* },
* revision_metadata_keys = {
* "revision_user" = "revision_user",
* "revision_created" = "revision_timestamp",
* "revision_log_message" = "revision_log"
* },
Expand Down
1 change: 1 addition & 0 deletions src/Entity/EntityMetaRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* "uuid" = "uuid"
* },
* revision_metadata_keys = {
* "revision_user" = "revision_user",
* "revision_created" = "revision_timestamp",
* "revision_log_message" = "revision_log"
* },
Expand Down
2 changes: 1 addition & 1 deletion src/EntityMetaListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function buildHeader() {
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\emr\Entity\EntityMetaInterface */
$row['id'] = $entity->link();
$row['id'] = $entity->toLink()->toString();
$row['status'] = $entity->isEnabled() ? $this->t('Enabled') : $this->t('Disabled');
return $row + parent::buildRow($entity);
}
Expand Down
2 changes: 1 addition & 1 deletion src/EntityMetaRelationListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function buildHeader() {
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\emr\Entity\EntityMetaRelationInterface */
$row['id'] = $entity->link();
$row['id'] = $entity->toLink()->toString();
return $row + parent::buildRow($entity);
}

Expand Down
Loading

0 comments on commit 88a9c1f

Please sign in to comment.