Added redirects to client screen after adding or deleting a linked client

This commit is contained in:
Naomi 2021-07-20 14:48:50 +02:00
parent d151b1744e
commit 73d9d6490a
3 changed files with 27 additions and 15 deletions

View File

@ -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 */ /* remove "details" accordion, see https://drupal.stackexchange.com/questions/294312/why-has-this-details-accordion-appeared-in-this-view */
.views-table details { .views-table details {
display: none; display: none;
}
form.oc-organisation-relation-form tr:first-child {
display: none;
} }

View File

@ -46,7 +46,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
* }, * },
* links = { * links = {
* "canonical" = "/opencase/oc_organisation_relation/{oc_organisation_relation}", * "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}", * "add-form" = "/opencase/oc_organisation_relation/add/{oc_organisation_relation_type}",
* "edit-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/edit", * "edit-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/edit",
* "delete-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/delete", * "delete-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/delete",
@ -110,12 +110,6 @@ class OCOrganisationRelation extends ContentEntityBase implements OCOrganisation
->setDefaultValue('Link between organisations') ->setDefaultValue('Link between organisations')
->setRequired(TRUE); ->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') $fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created')) ->setLabel(t('Created'))
->setDescription(t('The time that the entity was 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.')); ->setDescription(t('The time that the entity was last edited.'));
$fields['organisations'] = BaseFieldDefinition::create('entity_reference') $fields['organisations'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Organisations')) ->setLabel(t('Organisation to Link To'))
->setDescription(t('Linked organisations'))
->setSetting('target_type', 'oc_organisation') ->setSetting('target_type', 'oc_organisation')
->setSetting('handler', 'default') ->setSetting('handler', 'default')
->setCardinality(2) ->setCardinality(2)
@ -144,13 +137,15 @@ class OCOrganisationRelation extends ContentEntityBase implements OCOrganisation
->setDisplayOptions('view', [ ->setDisplayOptions('view', [
'label' => 'above', 'label' => 'above',
]) ])
->setDefaultValueCallback('opencase_entities_organisation_relation_callback') ->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE)
->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCOrganisationRelation::defaultValueCallback')
->setRequired(TRUE); ->setRequired(TRUE);
return $fields; return $fields;
} }
function defaultValueCallback() {
return [\Drupal::request()->query->get('organisation_id')];
}
} }
function opencase_entities_organisation_relation_callback() {
return [\Drupal::request()->query->get('organisation_id')];
}

View File

@ -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]);
}