diff --git a/css/opencase.css b/css/opencase.css index 595754b..31b0754 100644 --- a/css/opencase.css +++ b/css/opencase.css @@ -46,3 +46,27 @@ body { td.views-field { vertical-align: top; } + +/* Entity displays */ +.oc_entity .left { + display: inline-block; + width: 45%; + padding: 1em; +} + +.oc_entity .right { + display: inline-block; + width: 45%; + padding: 1em; + float: right; +} +.oc_entity .field { + margin-top: 1em; +} + +/* Make entity reference field labels match normal field labels */ +.field--type-entity-reference .field__label { + font-family: Georgia, "Times New Roman", Times, serif; + font-size: 1em !important; + font-weight: bold !important; +} diff --git a/modules/opencase_entities/oc_actor.page.inc b/modules/opencase_entities/oc_actor.page.inc index d17f583..88f346e 100644 --- a/modules/opencase_entities/oc_actor.page.inc +++ b/modules/opencase_entities/oc_actor.page.inc @@ -20,11 +20,17 @@ use Drupal\Core\Render\Element; * - attributes: HTML attributes for the containing element. */ function template_preprocess_oc_actor(array &$variables) { - // Fetch OCActor Entity Object. - $oc_actor = $variables['elements']['#oc_actor']; - - // Helpful $content variable for templates. + // Make the id available to the template and also separate the fields + // into two sections to be displayed in two columns. + $variables['id'] = $variables['elements']['#oc_actor']->get('id')[0]->get('value')->getValue(); + $variables['contact_details'] = array(); + $variables['fields_other_than_contact_details'] = array(); foreach (Element::children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; + if (in_array($key, ['email', 'phone', 'phone2', 'postal_address', 'post_code'])) { + $variables['contact_details'][$key] = $variables['elements'][$key]; + } else { + $variables['fields_other_than_contact_details'][$key] = $variables['elements'][$key]; + } } } diff --git a/modules/opencase_entities/oc_case.page.inc b/modules/opencase_entities/oc_case.page.inc index eefb297..6de9601 100644 --- a/modules/opencase_entities/oc_case.page.inc +++ b/modules/opencase_entities/oc_case.page.inc @@ -20,11 +20,18 @@ use Drupal\Core\Render\Element; * - attributes: HTML attributes for the containing element. */ function template_preprocess_oc_case(array &$variables) { - // Fetch OCCase Entity Object. - $oc_case = $variables['elements']['#oc_case']; - - // Helpful $content variable for templates. + // Separate the fields into two sections to be displayed in two columns. + // Remove the name (title) field as this is displayed anyway. + $variables['id'] = $variables['elements']['#oc_case']->get('id')[0]->get('value')->getValue(); + $variables['base_fields'] = array(); + $variables['other_fields'] = array(); foreach (Element::children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; + if (in_array($key, ['created', 'changed', 'files', 'actors_involved', 'status', 'user_id'])) { + $variables['base_fields'][$key] = $variables['elements'][$key]; + } else { + $variables['other_fields'][$key] = $variables['elements'][$key]; + unset($variables['other_fields']['name']); + } } } diff --git a/modules/opencase_entities/opencase_entities.install b/modules/opencase_entities/opencase_entities.install index 66b6f14..4641826 100644 --- a/modules/opencase_entities/opencase_entities.install +++ b/modules/opencase_entities/opencase_entities.install @@ -1,5 +1,62 @@ getFieldStorageDefinition('created', 'oc_case'); + $properties = array( + 'targetEntityType' => $field->getTargetEntityTypeId(), + 'bundle' => $field->getTargetBundle() + ); + if ($view_displays = \Drupal::entityTypeManager()->getStorage('entity_view_display')->loadByProperties($properties)) { + foreach ($view_displays as $view_display) { + $view_display->setComponent('created', array( + 'type' => 'datetime_default', + 'settings' => ['format_type' => 'short'], + ) + $component)->save(); + } + } +} + +// Make contact details revisionable. +function opencase_entities_update_80191() { + $update_manager = \Drupal::entityDefinitionUpdateManager(); + $contact_details_fields = ['email', 'phone', 'phone2', 'postal_address', 'post_code']; + foreach($contact_details_fields as $field) { + $definition = $update_manager->getFieldStorageDefinition($field, 'oc_actor'); + $definition->setRevisionable(TRUE); + } +} + +use \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter; + +/** + * Update my_entity to be revisionable. + */ +function opencase_entities_update_8019(&$sandbox) { + $schema_converter = new SqlContentEntityStorageSchemaConverter( + 'oc_actor', + \Drupal::entityTypeManager(), + \Drupal::entityDefinitionUpdateManager(), + \Drupal::service('entity.last_installed_schema.repository'), + \Drupal::keyValue('entity.storage_schema.sql'), + \Drupal::database() + ); + + $contact_details_fields = ['email', 'phone', 'phone2', 'postal_address', 'post_code']; + $schema_converter->convertToRevisionable($sandbox, $contact_details_fields); +} + +// Make contact details revisionable. +function opencase_entities_update_8018() { + $update_manager = \Drupal::entityDefinitionUpdateManager(); + $contact_details_fields = ['email', 'phone', 'phone2', 'postal_address', 'post_code']; + foreach($contact_details_fields as $field) { + $definition = $update_manager->getFieldStorageDefinition($field, 'oc_actor'); + $update_manager->updateFieldStorageDefinition($definition); + } +} + function opencase_entities_update_8016() { $update_manager = \Drupal::entityDefinitionUpdateManager(); $definition = $update_manager->getFieldStorageDefinition('activity_date_time', 'oc_activity'); @@ -30,4 +87,3 @@ function opencase_entities_update_8003() { \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('activity_date_time', 'oc_activity', 'oc_activity', $storage_definition); } - diff --git a/modules/opencase_entities/src/Entity/OCActor.php b/modules/opencase_entities/src/Entity/OCActor.php index b7215e1..5d4d60b 100644 --- a/modules/opencase_entities/src/Entity/OCActor.php +++ b/modules/opencase_entities/src/Entity/OCActor.php @@ -247,11 +247,6 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'text_processing' => 0, ]) ->setDefaultValue('') - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -9, - ]) ->setDisplayOptions('form', [ 'type' => 'string_textfield', 'weight' => -9, @@ -267,11 +262,6 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'text_processing' => 0, ]) ->setDefaultValue('') - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -8, - ]) ->setDisplayOptions('form', [ 'type' => 'string_textfield', 'weight' => -8, @@ -287,11 +277,6 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'text_processing' => 0, ]) ->setDefaultValue('') - ->setDisplayOptions('view', [ - 'label' => 'above', - 'type' => 'string', - 'weight' => -7, - ]) ->setDisplayOptions('form', [ 'type' => 'string_textfield', 'weight' => -7, @@ -313,6 +298,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface // so it is not exposed to user configuration. $fields['email'] = BaseFieldDefinition::create('string') ->setLabel(t('Email Address')) + ->setRevisionable(TRUE) ->setSettings(array( 'default_value' => '', 'max_length' => 30, @@ -329,6 +315,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface )); $fields['phone'] = BaseFieldDefinition::create('string') ->setLabel(t('Main Phone Number')) + ->setRevisionable(TRUE) ->setSettings(array( 'default_value' => '', 'max_length' => 20, @@ -344,6 +331,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'weight' => -4, )); $fields['phone2'] = BaseFieldDefinition::create('string') + ->setRevisionable(TRUE) ->setLabel(t('Alternative Phone Number')) ->setSettings(array( 'default_value' => '', @@ -360,6 +348,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'weight' => -3, )); $fields['postal_address'] = BaseFieldDefinition::create('string_long') + ->setRevisionable(TRUE) ->setLabel(t('Postal Address')) ->setDescription(t('Full address, apart from post code.')) ->setSettings(array( @@ -377,6 +366,7 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface 'weight' => -2, )); $fields['post_code'] = BaseFieldDefinition::create('string') + ->setRevisionable(TRUE) ->setLabel(t('Post Code')) ->setSettings(array( 'default_value' => '', diff --git a/modules/opencase_entities/src/Entity/OCCase.php b/modules/opencase_entities/src/Entity/OCCase.php index 3ce95a2..1467744 100644 --- a/modules/opencase_entities/src/Entity/OCCase.php +++ b/modules/opencase_entities/src/Entity/OCCase.php @@ -222,16 +222,15 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface { ->setDefaultValue(TRUE); $fields['user_id'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Entered by')) + ->setLabel(t('Created by')) ->setDescription(t('The user ID of author of the Case entity.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'user') ->setSetting('handler', 'default') ->setTranslatable(TRUE) ->setDisplayOptions('view', [ - 'label' => 'inline', + 'label' => 'above', 'type' => 'author', - 'weight' => -4, ]); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Case Title')) @@ -245,7 +244,6 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface { ->setDisplayOptions('view', [ 'label' => 'hidden', 'type' => 'string', - 'weight' => -3, ]) ->setDisplayOptions('form', [ 'type' => 'string_textfield', @@ -261,6 +259,7 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface { ->setTranslatable(TRUE) ->setCardinality(-1) ->setDisplayOptions('form', [ + 'label' => 'above', 'type' => 'entity_reference_autocomplete', 'weight' => -2, 'settings' => [ @@ -272,7 +271,6 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface { ]) ->setDisplayOptions('view', [ 'label' => 'above', - 'weight' => -2 ]) ->setDefaultValueCallback('Drupal\opencase_entities\Entity\OCCase::defaultVal') ->setRequired(TRUE); @@ -295,17 +293,30 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface { ]) ->setDisplayOptions('view', [ 'label' => 'above', - 'weight' => -1, 'settings' => ['use_description_as_link_text' => 'true'] ]); $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the entity was created.')); + ->setLabel(t('Created on')) + ->setDescription(t('When the case was created.')) + ->setDisplayOptions('view', [ + 'type' => "datetime_default", + 'label' => 'above', + 'settings' => [ + 'date_format' => 'short' + ] + ]); $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')); + ->setLabel(t('Last updated')) + ->setDescription(t('When the case was last edited.')) + ->setDisplayOptions('view', [ + 'type' => "datetime_custom", + 'label' => 'above', + 'settings' => [ + 'date_format' => 'm/d/Y' + ] + ]); $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Revision translation affected')) diff --git a/modules/opencase_entities/src/Form/OCActorForm.php b/modules/opencase_entities/src/Form/OCActorForm.php index d828e9d..6ba0230 100644 --- a/modules/opencase_entities/src/Form/OCActorForm.php +++ b/modules/opencase_entities/src/Form/OCActorForm.php @@ -38,18 +38,11 @@ class OCActorForm extends ContentEntityForm { */ public function save(array $form, FormStateInterface $form_state) { $entity = $this->entity; - - // Save as a new revision if requested to do so. - if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) { - $entity->setNewRevision(); - - // If a new revision is created, save the current user as revision author. - $entity->setRevisionCreationTime(REQUEST_TIME); - $entity->setRevisionUserId(\Drupal::currentUser()->id()); - } - else { - $entity->setNewRevision(FALSE); - } + // Always make a new revision for a person. They are not changed often and people are likely to + // want to know what has happened to them over time. + $entity->setNewRevision(); + $entity->setRevisionCreationTime(REQUEST_TIME); + $entity->setRevisionUserId(\Drupal::currentUser()->id()); $status = parent::save($form, $form_state); diff --git a/modules/opencase_entities/templates/oc_actor.html.twig b/modules/opencase_entities/templates/oc_actor.html.twig index e92f6da..a04e68d 100644 --- a/modules/opencase_entities/templates/oc_actor.html.twig +++ b/modules/opencase_entities/templates/oc_actor.html.twig @@ -16,7 +16,20 @@ */ #}