From 73d9d6490a455504deff720effd0b098bcccaba5 Mon Sep 17 00:00:00 2001 From: Naomi Date: Tue, 20 Jul 2021 14:48:50 +0200 Subject: [PATCH] Added redirects to client screen after adding or deleting a linked client --- css/opencase.css | 6 ++++-- .../src/Entity/OCOrganisationRelation.php | 21 +++++++------------ opencase.module | 15 +++++++++++++ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/css/opencase.css b/css/opencase.css index 01f8a2b..95995fa 100644 --- a/css/opencase.css +++ b/css/opencase.css @@ -117,7 +117,9 @@ table.views-table.views-view-table caption { /* remove "details" accordion, see https://drupal.stackexchange.com/questions/294312/why-has-this-details-accordion-appeared-in-this-view */ .views-table details { - display: none; - +} + +form.oc-organisation-relation-form tr:first-child { + display: none; } diff --git a/modules/opencase_entities/src/Entity/OCOrganisationRelation.php b/modules/opencase_entities/src/Entity/OCOrganisationRelation.php index 0b43948..cb238b7 100644 --- a/modules/opencase_entities/src/Entity/OCOrganisationRelation.php +++ b/modules/opencase_entities/src/Entity/OCOrganisationRelation.php @@ -46,7 +46,7 @@ use Drupal\Core\Entity\EntityTypeInterface; * }, * links = { * "canonical" = "/opencase/oc_organisation_relation/{oc_organisation_relation}", - * "add-page" = "/opencase//oc_organisation_relation/add", + * "add-page" = "/opencase/oc_organisation_relation/add", * "add-form" = "/opencase/oc_organisation_relation/add/{oc_organisation_relation_type}", * "edit-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/edit", * "delete-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/delete", @@ -110,12 +110,6 @@ class OCOrganisationRelation extends ContentEntityBase implements OCOrganisation ->setDefaultValue('Link between organisations') ->setRequired(TRUE); - $fields['status']->setDescription(t('A boolean indicating whether the Organisation Relation is published.')) - ->setDisplayOptions('form', [ - 'type' => 'boolean_checkbox', - 'weight' => -3, - ]); - $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Created')) ->setDescription(t('The time that the entity was created.')); @@ -125,8 +119,7 @@ class OCOrganisationRelation extends ContentEntityBase implements OCOrganisation ->setDescription(t('The time that the entity was last edited.')); $fields['organisations'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Organisations')) - ->setDescription(t('Linked organisations')) + ->setLabel(t('Organisation to Link To')) ->setSetting('target_type', 'oc_organisation') ->setSetting('handler', 'default') ->setCardinality(2) @@ -144,13 +137,15 @@ class OCOrganisationRelation extends ContentEntityBase implements OCOrganisation ->setDisplayOptions('view', [ 'label' => 'above', ]) - ->setDefaultValueCallback('opencase_entities_organisation_relation_callback') + ->setDisplayConfigurable('view', TRUE) + ->setDisplayConfigurable('form', TRUE) + ->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCOrganisationRelation::defaultValueCallback') ->setRequired(TRUE); return $fields; } + function defaultValueCallback() { + return [\Drupal::request()->query->get('organisation_id')]; + } } -function opencase_entities_organisation_relation_callback() { - return [\Drupal::request()->query->get('organisation_id')]; -} diff --git a/opencase.module b/opencase.module index f5e59da..64f290d 100644 --- a/opencase.module +++ b/opencase.module @@ -114,3 +114,18 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini } +/** + * Implementation of hook_form_alter() + * Changes what page is redirected to after adding or deleting linked organisation + */ +function opencase_form_alter(&$form, &$form_state, $form_id) { + if (preg_match('/oc_organisation_relation_.*_delete_form/', $form_id) or (preg_match('/oc_organisation_relation_.*_add_form/', $form_id))) { + $form['actions']['submit']['#submit'][] = '_opencase_organisation_relation_redirect'; + // $form['actions']['cancel']['#url'] = $form_state->getFormObject()->getEntity()->toUrl(); + } +} + +function _opencase_organisation_relation_redirect($form, &$form_state) { + $organisation_id = \Drupal::request()->query->get('organisation_id'); + $form_state->setRedirect('entity.oc_organisation.canonical', ['oc_organisation' => $organisation_id]); +}