-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from openeuropa/OPENEUROPA-3272
OPENEUROPA-3272: Create oe_list_pages entity meta bundle and plugin.
- Loading branch information
Showing
20 changed files
with
989 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
18 changes: 18 additions & 0 deletions
18
config/install/field.field.entity_meta.oe_list_page.oe_list_page_config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
18 changes: 18 additions & 0 deletions
18
config/install/field.field.entity_meta.oe_list_page.oe_list_page_source.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
config/install/field.storage.entity_meta.oe_list_page_config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
config/install/field.storage.entity_meta.oe_list_page_source.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
Oops, something went wrong.