Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENEUROPA-3272: Create oe_list_pages entity meta bundle and plugin. #2

Merged
merged 19 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ services:
image: percona/percona-server:5.6
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
selenium:
image: selenium/standalone-chrome:3.141.5
shm_size: 2g
environment:
- DISPLAY=:99
- SCREEN_WIDTH=1280
- SCREEN_HEIGHT=800
- NODE_MAX_INSTANCES=5
- NODE_MAX_SESSION=5

pipeline:
composer-install:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prefer-stable": true,
"require": {
"drupal/core": "^8.8",
"openeuropa/entity_meta_relation": "dev-OPENEUROPA-3271",
"openeuropa/entity_meta_relation": "dev-8.x-1.x",
"drupal/search_api": "~1.17",
"php": ">=7.2"
},
Expand Down
5 changes: 5 additions & 0 deletions config/install/emr.entity_meta_type.oe_list_page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
langcode: en
status: true
dependencies: { }
id: oe_list_page
label: 'List Page'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
config:
- emr.entity_meta_type.oe_list_page
- field.storage.entity_meta.oe_list_page_config
id: entity_meta.oe_list_page.oe_list_page_config
field_name: oe_list_page_config
entity_type: entity_meta
bundle: oe_list_page
label: 'List Pages configuration'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string_long
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
config:
- emr.entity_meta_type.oe_list_page
- field.storage.entity_meta.oe_list_page_source
id: entity_meta.oe_list_page.oe_list_page_source
field_name: oe_list_page_source
entity_type: entity_meta
bundle: oe_list_page
label: 'List Pages source'
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
18 changes: 18 additions & 0 deletions config/install/field.storage.entity_meta.oe_list_page_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
module:
- emr
id: entity_meta.oe_list_page_config
field_name: oe_list_page_config
entity_type: entity_meta
type: string_long
settings:
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
20 changes: 20 additions & 0 deletions config/install/field.storage.entity_meta.oe_list_page_source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
module:
- emr
id: entity_meta.oe_list_page_source
field_name: oe_list_page_source
entity_type: entity_meta
type: string
settings:
max_length: 255
is_ascii: false
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ services:
# ports:
# - 3306:3306

# If you would like to see what is going on you can run the following on your host:
# docker run --rm -p 4444:4444 -p 5900:5900 --network="host" selenium/standalone-chrome-debug:latest
# Newer version of this image might run into this issue:
# @link https://github.com/elgalu/docker-selenium/issues/20
selenium:
image: selenium/standalone-chrome-debug:3.141.59-oxygen
expose:
- '4444'
environment:
- DISPLAY=:99
- SE_OPTS=-debug
- SCREEN_WIDTH=1280
- SCREEN_HEIGHT=800
- VNC_NO_PASSWORD=1
ports:
- '4444:4444'
- "5900:5900"
volumes:
- /dev/shm:/dev/shm
shm_size: 2g

#### Mac users: uncomment the "volumes" key to enable the NFS file sharing. You can find more information about Docker for Mac here: https://github.com/openeuropa/openeuropa/blob/master/docs/starting/tooling.md#using-docker-on-macos

#volumes:
Expand Down
10 changes: 9 additions & 1 deletion oe_list_pages.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ type: module
core: 8.x

dependencies:
- emr_node:emr_node
- emr:emr_node
- search_api:search_api

config_devel:
install:
- emr.entity_meta_type.oe_list_page
- field.field.entity_meta.oe_list_page.list_page_plugin
- field.field.entity_meta.oe_list_page.list_page_plugin_config
- field.storage.entity_meta.list_page_plugin
- field.storage.entity_meta.list_page_plugin_config
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<env name="SIMPLETEST_IGNORE_DIRECTORIES" value="${drupal.root}"/>
<env name="SIMPLETEST_BASE_URL" value="${drupal.base_url}"/>
<env name="SIMPLETEST_DB" value="mysql://${drupal.database.user}:${drupal.database.password}@${drupal.database.host}:${drupal.database.port}/${drupal.database.name}"/>
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["${selenium.browser}", null, "${selenium.host}:${selenium.port}/wd/hub"]'/>
</php>
<testsuites>
<testsuite>
Expand Down
6 changes: 6 additions & 0 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ drupal:
- "vendor"
- "${drupal.root}"


selenium:
host: "http://selenium"
port: "4444"
browser: "chrome"

commands:
drupal:site-setup:
- { task: "symlink", from: "../../..", to: "${drupal.root}/modules/custom/oe_list_pages" }
Expand Down
26 changes: 26 additions & 0 deletions src/ListPageEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_list_pages;

/**
* Contains all events thrown in the oe_list_pages component.
*/
final class ListPageEvents {

/**
* Event fired when altering the entity types.
*
* @var string
*/
const ALTER_ENTITY_TYPES = 'oe_list_pages.entity_types_alter';

/**
* Event fired when altering the bundles.
*
* @var string
*/
const ALTER_BUNDLES = 'oe_list_pages.bundles_alter';

}
87 changes: 87 additions & 0 deletions src/ListPageSourceAlterEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_list_pages;

use Symfony\Component\EventDispatcher\Event;

/**
* Event thrown in order to alter the list source.
*
* The entity types and bundles that can be selected for a list source can
* be altered by subscribing to this event.
*/
class ListPageSourceAlterEvent extends Event {

/**
* The list of entity types.
*
* @var array
*/
protected $entityTypes;

/**
* The list of bundles.
*
* @var array
*/
protected $bundles;

/**
* Constructs a new ListPageSourceAlterEvent.
*
* @param array $entity_types
* The list of entity type ids.
* @param array $bundles
* The list of entity bundles.
*/
public function __construct(array $entity_types, array $bundles = []) {
$this->entityTypes = $entity_types;
$this->bundles = $bundles;
}

/**
* Returns the allowed entity types.
*
* @return string[]
* The list of entity types.
*/
public function getEntityTypes(): array {
return $this->entityTypes;
}

/**
* Set the allowed entity types.
*
* @param array $entity_types
* The list of entity types.
*/
public function setEntityTypes(array $entity_types): void {
$this->entityTypes = $entity_types;
}

/**
* Returns the allowed bundles.
*
* @return string[]
* The list of allowed bundles.
*/
public function getBundles(): array {
return $this->bundles;
}

/**
* Set the allowed bundles.
*
* @param string $entity_type
* The entity type.
* @param array $bundles
* The bundles.
*/
public function setBundles(string $entity_type, array $bundles): void {
$this->entityTypes = [$entity_type];
$this->bundles = $bundles;
}

}
91 changes: 91 additions & 0 deletions src/ListPageWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_list_pages;

use Drupal\emr\EntityMetaWrapper;

/**
* Wrapper for the list page entity meta.
*/
class ListPageWrapper extends EntityMetaWrapper {

/**
* Set the entity/bundle pair for the list page source.
*
* @param string $entity_type
* Entity type name.
* @param string $bundle
* Bundle of entity type.
*/
public function setSource(string $entity_type, string $bundle): void {
$this->entityMeta->set('oe_list_page_source', $entity_type . ':' . $bundle);
}

/**
* Returns the entity meta list page source.
*
* This is a pair of entity_type:bundle that will be used for querying on this
* list page.
*
* @return string|null
* The entity_type:bundle pair source.
*/
public function getSource(): ?string {
return $this->entityMeta->get('oe_list_page_source')->value;
}

/**
* Returns the entity type used as the source.
*
* @return string|null
* The entity type.
*/
public function getSourceEntityType(): ?string {
$source = $this->getSource();
if (!$source) {
return NULL;
}

list($entity_type, $bundle) = explode(':', $source);
return $entity_type;
}

/**
* Returns the bundle used in the source.
*
* @return string|null
* The bundle.
*/
public function getSourceEntityBundle(): ?string {
$source = $this->getSource();
if (!$source) {
return NULL;
}

list($entity_type, $bundle) = explode(':', $source);
return $bundle;
}

/**
* Returns the entity meta configuration.
*
* @return array
* The list page configuration.
*/
public function getConfiguration(): array {
return $this->entityMeta->get('oe_list_page_config')->isEmpty() ? [] : unserialize($this->entityMeta->get('oe_list_page_config')->value);
}

/**
* Sets the entity meta configuration.
*
* @param array $configuration
* The list page configuration.
*/
public function setConfiguration(array $configuration): void {
$this->entityMeta->set('oe_list_page_config', serialize($configuration));
}

}
Loading