diff --git a/config/schema/field_inheritance.schema.yml b/config/schema/field_inheritance.schema.yml new file mode 100644 index 0000000000000000000000000000000000000000..0bde2530d5d0abd2befea9c964422d6cbce2f5c5 --- /dev/null +++ b/config/schema/field_inheritance.schema.yml @@ -0,0 +1,20 @@ +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 diff --git a/modules/recurring_events_registration/src/NotificationService.php b/modules/recurring_events_registration/src/NotificationService.php index 4bfe616dd5994b0ebd267605cc0e66a03e1efed7..2f63bd255adb5c01ab87adf36f82d7c7ae9d5842 100644 --- a/modules/recurring_events_registration/src/NotificationService.php +++ b/modules/recurring_events_registration/src/NotificationService.php @@ -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; diff --git a/recurring_events.links.action.yml b/recurring_events.links.action.yml new file mode 100644 index 0000000000000000000000000000000000000000..9f3ca0df56c833b05f55a1f1f7d5a09eb5a5b53a --- /dev/null +++ b/recurring_events.links.action.yml @@ -0,0 +1,6 @@ +entity.field_inheritance.add_form: + route_name: entity.field_inheritance.add_form + title: 'Add Field inheritance' + appears_on: + - entity.field_inheritance.collection + diff --git a/recurring_events.links.task.yml b/recurring_events.links.task.yml index f142147e81dde7d982c0b3801b3380b17ce09acc..2b584d41004697189be9525e06152749afb9149d 100644 --- a/recurring_events.links.task.yml +++ b/recurring_events.links.task.yml @@ -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 diff --git a/recurring_events.services.yml b/recurring_events.services.yml index 21ab96046d87932f290f0f53cbf0533d6b6038ef..b0f5718fd5df7655d5008055a6b0d9a39f770cc6 100644 --- a/recurring_events.services.yml +++ b/recurring_events.services.yml @@ -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 diff --git a/src/Entity/FieldInheritance.php b/src/Entity/FieldInheritance.php new file mode 100644 index 0000000000000000000000000000000000000000..6e94ca6ba167f365e95cf4145c30bc95a085e6ac --- /dev/null +++ b/src/Entity/FieldInheritance.php @@ -0,0 +1,153 @@ +<?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; + } + +} diff --git a/src/Entity/FieldInheritanceInterface.php b/src/Entity/FieldInheritanceInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..6d15b4365c72535babed869a77f46448ec6f9557 --- /dev/null +++ b/src/Entity/FieldInheritanceInterface.php @@ -0,0 +1,84 @@ +<?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); + +} diff --git a/src/FieldInheritanceFactory.php b/src/FieldInheritanceFactory.php index b8a2120cea64cbfaeeba4ea1ab34002a08872f67..a60900b28170ba06273ddd438877c5dded80bc6b 100644 --- a/src/FieldInheritanceFactory.php +++ b/src/FieldInheritanceFactory.php @@ -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'); diff --git a/src/FieldInheritanceHtmlRouteProvider.php b/src/FieldInheritanceHtmlRouteProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..dd0fba9ebdcad329ca3195296f0d61a88ca6942b --- /dev/null +++ b/src/FieldInheritanceHtmlRouteProvider.php @@ -0,0 +1,28 @@ +<?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; + } + +} diff --git a/src/FieldInheritanceListBuilder.php b/src/FieldInheritanceListBuilder.php new file mode 100644 index 0000000000000000000000000000000000000000..e2e029bca4293ff0d3d1aa5405f7801176f82e80 --- /dev/null +++ b/src/FieldInheritanceListBuilder.php @@ -0,0 +1,37 @@ +<?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); + } + +} diff --git a/src/FieldInheritanceManager.php b/src/FieldInheritancePluginManager.php similarity index 91% rename from src/FieldInheritanceManager.php rename to src/FieldInheritancePluginManager.php index 63dfeeec36107cefc2150e65bd59ea8ff379e110..6ab747982a15a777d13db59530e0f029c53602d3 100644 --- a/src/FieldInheritanceManager.php +++ b/src/FieldInheritancePluginManager.php @@ -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 diff --git a/src/Form/FieldInheritanceDeleteForm.php b/src/Form/FieldInheritanceDeleteForm.php new file mode 100644 index 0000000000000000000000000000000000000000..0b27877f0f7e13ee6ea05dd1a62eab2d2f2d77bb --- /dev/null +++ b/src/Form/FieldInheritanceDeleteForm.php @@ -0,0 +1,53 @@ +<?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()); + } + +} diff --git a/src/Form/FieldInheritanceForm.php b/src/Form/FieldInheritanceForm.php new file mode 100644 index 0000000000000000000000000000000000000000..125932c4082f93dde69a04e80d9559a3d460a86e --- /dev/null +++ b/src/Form/FieldInheritanceForm.php @@ -0,0 +1,133 @@ +<?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')); + } + +}