Skip to content
Snippets Groups Projects
Commit afa6c843 authored by Owen Bush's avatar Owen Bush
Browse files

Initial commit of inheritance config entity

parent f98e1896
No related branches found
No related tags found
No related merge requests found
Showing with 534 additions and 19 deletions
recurring_events.field_inheritance.*:
type: config_entity
label: 'Field inheritance config'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
uuid:
type: string
type:
type: string
sourceField:
type: string
entityField:
type: string
plugin:
type: string
......@@ -133,7 +133,7 @@ class NotificationService {
* @param \Drupal\recurring_events_registration\Entity\RegistrantInterface $registrant
* The registrant entity.
*
* @return self
* @return $this
* The NotificationService object.
*/
public function setEntity(RegistrantInterface $registrant) {
......@@ -147,8 +147,7 @@ class NotificationService {
* @param string $key
* The email key to use.
*
* @return self
* The NotificationService object.
* @return $this
*/
public function setKey($key) {
$this->key = $key;
......@@ -161,8 +160,7 @@ class NotificationService {
* @param string $subject
* The email subject line.
*
* @return self
* The NotificationService object.
* @return $this
*/
public function setSubject($subject) {
$this->subject = $subject;
......@@ -175,8 +173,7 @@ class NotificationService {
* @param string $message
* The email message.
*
* @return self
* The NotificationService object.
* @return $this
*/
public function setMessage($message) {
$this->message = $message;
......@@ -189,8 +186,7 @@ class NotificationService {
* @param string $from
* The from email address.
*
* @return self
* The NotificationService object.
* @return $this
*/
public function setFrom($from) {
$this->from = $from;
......@@ -203,8 +199,7 @@ class NotificationService {
* @param string $name
* The name of the config value to use.
*
* @return self
* The NotificationService object.
* @return $this
*/
public function setConfigName($name) {
$this->configName = $name;
......
entity.field_inheritance.add_form:
route_name: entity.field_inheritance.add_form
title: 'Add Field inheritance'
appears_on:
- entity.field_inheritance.collection
......@@ -55,13 +55,19 @@ eventinstance.clone_form:
weight: 11
# Event Series settings admin page.
eventseries.settings_tab:
entity.eventseries.settings:
route_name: eventseries.settings
title: Event Series Settings
base_route: eventseries.settings
# Event Instance settings admin page.
eventinstance.settings_tab:
entity.eventinstance.settings:
route_name: eventinstance.settings
title: Event Instance Settings
base_route: eventinstance.settings
# Field Inheritance settings admin page.
entity.field_inheritance.collection:
route_name: entity.field_inheritance.collection
title: Field Inheritance
base_route: eventinstance.settings
\ No newline at end of file
......@@ -3,5 +3,5 @@ services:
class: Drupal\recurring_events\EventCreationService
arguments: ['@string_translation', '@database', '@logger.factory', '@messenger', '@date.formatter']
plugin.manager.field_inheritance:
class: Drupal\recurring_events\FieldInheritanceManager
class: Drupal\recurring_events\FieldInheritancePluginManager
parent: default_plugin_manager
<?php
namespace Drupal\recurring_events\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
/**
* Defines the Field inheritance entity.
*
* @ConfigEntityType(
* id = "field_inheritance",
* label = @Translation("Field inheritance"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\recurring_events\FieldInheritanceListBuilder",
* "form" = {
* "add" = "Drupal\recurring_events\Form\FieldInheritanceForm",
* "edit" = "Drupal\recurring_events\Form\FieldInheritanceForm",
* "delete" = "Drupal\recurring_events\Form\FieldInheritanceDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\recurring_events\FieldInheritanceHtmlRouteProvider",
* },
* },
* config_prefix = "field_inheritance",
* admin_permission = "administer site configuration",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/admin/structure/events/instance/settings/field_inheritance/{field_inheritance}",
* "add-form" = "/admin/structure/events/instance/settings/field_inheritance/add",
* "edit-form" = "/admin/structure/events/instance/settings/field_inheritance/{field_inheritance}/edit",
* "delete-form" = "/admin/structure/events/instance/settings/field_inheritance/{field_inheritance}/delete",
* "collection" = "/admin/structure/events/instance/settings/field_inheritance"
* },
* config_export = {
* "id",
* "label",
* "type",
* "sourceField",
* "entityField",
* "plugin"
* }
* )
*/
class FieldInheritance extends ConfigEntityBase implements FieldInheritanceInterface {
/**
* The field inheritance ID.
*
* @var string
*/
protected $id;
/**
* The field inheritance label.
*
* @var string
*/
protected $label;
/**
* The field inheritance type.
*
* @var string
*/
protected $type;
/**
* The field inheritance source field.
*
* @var string
*/
protected $sourceField;
/**
* The field inheritance entity field.
*
* @var string
*/
protected $entityField;
/**
* The field inheritance plugin.
*
* @var string
*/
protected $plugin;
/**
* {@inheritdoc}
*/
public function type() {
return isset($this->type) ? $this->type : NULL;
}
/**
* {@inheritdoc}
*/
public function sourceField() {
return isset($this->sourceField) ? $this->sourceField : NULL;
}
/**
* {@inheritdoc}
*/
public function entityField() {
return isset($this->entityField) ? $this->entityField : NULL;
}
/**
* {@inheritdoc}
*/
public function plugin() {
return isset($this->plugin) ? $this->plugin : NULL;
}
/**
* {@inheritdoc}
*/
public function setType($type) {
$this->type = $type;
return $this;
}
/**
* {@inheritdoc}
*/
public function setSourceField($source_field) {
$this->sourceField = $source_field;
return $this;
}
/**
* {@inheritdoc}
*/
public function setEntityField($entity_field) {
$this->entityField = $entity_field;
return $this;
}
/**
* {@inheritdoc}
*/
public function setPlugin($plugin) {
$this->plugin = $plugin;
return $this;
}
}
<?php
namespace Drupal\recurring_events\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for defining Field inheritance entities.
*/
interface FieldInheritanceInterface extends ConfigEntityInterface {
/**
* Get the inheritance type.
*
* @return string
* The inheritance type.
*/
public function type();
/**
* Get the inheritance source field.
*
* @return string
* The inheritance source field.
*/
public function sourceField();
/**
* Get the inheritance entity field.
*
* @return string
* The inheritance entity field.
*/
public function entityField();
/**
* Get the inheritance plugin.
*
* @return string
* The inheritance plugin.
*/
public function plugin();
/**
* Set the inheritance type.
*
* @var string $type
* The inheritance type.
*
* @return $this
*/
public function setType($type);
/**
* Set the inheritance source field.
*
* @var string $source_field
* The inheritance source field.
*
* @return $this
*/
public function setSourceField($source_field);
/**
* Set the inheritance entity field.
*
* @var string $entity_field
* The inheritance entity field.
*
* @return $this
*/
public function setEntityField($entity_field);
/**
* Set the inheritance plugin.
*
* @var string $plugin
* The inheritance plugin.
*
* @return $this
*/
public function setPlugin($plugin);
}
......@@ -57,10 +57,10 @@ class FieldInheritanceFactory extends FieldItemList {
}
/**
* Returns the FieldInheritanceManager plugin manager.
* Returns the FieldInheritancePluginManager plugin manager.
*
* @return \Drupal\recurring_events\FieldInheritanceManager
* The FieldInheritanceManager plugin manager.
* @return \Drupal\recurring_events\FieldInheritancePluginManager
* The FieldInheritancePluginManager plugin manager.
*/
protected function getManager() {
return \Drupal::service('plugin.manager.field_inheritance');
......
<?php
namespace Drupal\recurring_events;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Field inheritance entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class FieldInheritanceHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
// Provide your custom entity routes here.
return $collection;
}
}
<?php
namespace Drupal\recurring_events;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of Field inheritance entities.
*/
class FieldInheritanceListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('Field inheritance');
$header['id'] = $this->t('Machine name');
$header['type'] = $this->t('Type');
$header['source_field'] = $this->t('Source Field');
$header['entity_field'] = $this->t('Entity Field');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['type'] = $entity->type();
$row['source_field'] = $entity->sourceField();
$row['entity_field'] = $entity->entityField() ?: $this->t('N/A');
return $row + parent::buildRow($entity);
}
}
......@@ -13,10 +13,10 @@ use Drupal\Core\Plugin\DefaultPluginManager;
* @see \Drupal\recurring_events\FieldInheritancePluginInterface
* @see plugin_api
*/
class FieldInheritanceManager extends DefaultPluginManager {
class FieldInheritancePluginManager extends DefaultPluginManager {
/**
* Constructs a FieldInheritanceManager object.
* Constructs a FieldInheritancePluginManager object.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
......
<?php
namespace Drupal\recurring_events\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Builds the form to delete Field inheritance entities.
*/
class FieldInheritanceDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.field_inheritance.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label(),
]
)
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
<?php
namespace Drupal\recurring_events\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Class FieldInheritanceForm.
*/
class FieldInheritanceForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$field_inheritance = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $field_inheritance->label(),
'#description' => $this->t("Label for the Field inheritance."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $field_inheritance->id(),
'#machine_name' => [
'exists' => '\Drupal\recurring_events\Entity\FieldInheritance::load',
],
'#disabled' => !$field_inheritance->isNew(),
];
$help = [
$this->t('<b>Inherit</b> - Pull field data directly from the series.'),
$this->t('<b>Prepend</b> - Place instance data above series data.'),
$this->t('<b>Append</b> - Place instance data below series data.'),
$this->t('<b>Fallback</b> - Show instance data, if set, otherwise show series data.'),
];
$form['type'] = [
'#type' => 'select',
'#title' => $this->t('Inheritance Strategy'),
'#description' => $this->t('Select the method/strategy used to inherit data.'),
'#options' => [
'inherit' => $this->t('Inherit'),
'prepend' => $this->t('Prepend'),
'append' => $this->t('Append'),
'fallback' => $this->t('Fallback'),
],
'#required' => TRUE,
'#default_value' => $field_inheritance->type() ?: 'inherit',
];
$form['information'] = [
'#type' => 'markup',
'#prefix' => '<p>',
'#markup' => implode('</p><p>', $help),
'#suffix' => '</p>',
];
$series_fields = array_keys(\Drupal::service('entity_field.manager')->getFieldDefinitions('eventseries', 'eventseries'));
$series_fields = array_combine($series_fields, $series_fields);
$form['sourceField'] = [
'#type' => 'select',
'#title' => $this->t('Source/Series Field'),
'#description' => $this->t('Select the field on the series from which to inherit data.'),
'#options' => $series_fields,
'#required' => TRUE,
'#default_value' => $field_inheritance->sourceField(),
];
$instance_fields = array_keys(\Drupal::service('entity_field.manager')->getFieldDefinitions('eventinstance', 'eventinstance'));
$instance_fields = array_combine($instance_fields, $instance_fields);
$form['entityField'] = [
'#type' => 'select',
'#title' => $this->t('Entity/Instance Field'),
'#description' => $this->t('Select the field on the instance to use during inheritance.'),
'#options' => $instance_fields,
'#states' => [
'visible' => [
'select[name="type"]' => ['!value' => 'inherit'],
],
'required' => [
'select[name="type"]' => ['!value' => 'inherit'],
],
],
'#default_value' => $field_inheritance->entityField(),
];
$plugins = array_keys(\Drupal::service('plugin.manager.field_inheritance')->getDefinitions());
$plugins = array_combine($plugins, $plugins);
$form['plugin'] = [
'#type' => 'select',
'#title' => $this->t('Inheritance Plugin'),
'#description' => $this->t('Select the plugin used to perform the inheritance.'),
'#options' => $plugins,
'#required' => TRUE,
'#default_value' => $field_inheritance->plugin(),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$field_inheritance = $this->entity;
$status = $field_inheritance->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Field inheritance.', [
'%label' => $field_inheritance->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Field inheritance.', [
'%label' => $field_inheritance->label(),
]));
}
$form_state->setRedirectUrl($field_inheritance->toUrl('collection'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment