In progress of adding revision views & making entity displays nicer
This commit is contained in:
parent
b83f0b44b4
commit
18e32335f5
@ -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;
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,62 @@
|
||||
<?php
|
||||
|
||||
// Change date formats on created and changed dates.
|
||||
function opencase_entities_update_801910() {
|
||||
$update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$field = $update_manager->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);
|
||||
}
|
||||
|
||||
|
@ -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' => '',
|
||||
|
@ -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'))
|
||||
|
@ -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);
|
||||
|
||||
|
@ -16,7 +16,20 @@
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_actor') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
<div class="oc_entity">
|
||||
<div class="left">
|
||||
{% for field in fields_other_than_contact_details %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="right">
|
||||
<div id ="contact_details">
|
||||
<h2>Contact Details</h2>
|
||||
<a class="field" href="/opencase/oc_actor/{{ id }}/contact_details_history">See history</a>
|
||||
{% for field in contact_details %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -16,7 +16,18 @@
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_case') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
<h2>{{ title }}</h2>
|
||||
<div class="oc_entity">
|
||||
<div class="left">
|
||||
{{ base_fields.actors_involved }}
|
||||
{{ base_fields.changed }}
|
||||
{{ base_fields.created }}
|
||||
{{ base_fields.user_id }}
|
||||
</div>
|
||||
<div class="right">
|
||||
{% for field in other_fields %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -2,7 +2,7 @@ name: 'OpenCase'
|
||||
type: module
|
||||
description: 'Simple Case Management'
|
||||
core: 8.x
|
||||
version: 8.x-1.6.5
|
||||
version: 8.x-1.8
|
||||
package: 'OpenCase'
|
||||
dependencies:
|
||||
- opencase_entities
|
||||
|
Reference in New Issue
Block a user