Compare commits
2 Commits
f6792e5053
...
cfec9be05c
Author | SHA1 | Date | |
---|---|---|---|
cfec9be05c | |||
d483b3f47e |
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Drupal\Core\Render\Element;
|
use Drupal\Core\Render\Element;
|
||||||
|
use Drupal\opencase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares variables for Case templates.
|
* Prepares variables for Case templates.
|
||||||
@ -20,18 +21,6 @@ use Drupal\Core\Render\Element;
|
|||||||
* - attributes: HTML attributes for the containing element.
|
* - attributes: HTML attributes for the containing element.
|
||||||
*/
|
*/
|
||||||
function template_preprocess_oc_case(array &$variables) {
|
function template_preprocess_oc_case(array &$variables) {
|
||||||
// Separate the fields into two sections to be displayed in two columns.
|
_template_preprocess_entity($variables);
|
||||||
// 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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
#}
|
#}
|
||||||
<div{{ attributes.addClass('oc_case') }}>
|
<div{{ attributes.addClass('oc_case') }}>
|
||||||
{% if content %}
|
{% if normal_fields %}
|
||||||
{{- content -}}
|
<div id='static_data'>{{- normal_fields -}}</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if extra_fields %}
|
||||||
|
<div id='dynamic_data'>{{- extra_fields -}}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,11 +20,5 @@ use Drupal\Core\Render\Element;
|
|||||||
* - attributes: HTML attributes for the containing element.
|
* - attributes: HTML attributes for the containing element.
|
||||||
*/
|
*/
|
||||||
function template_preprocess_oc_organisation(array &$variables) {
|
function template_preprocess_oc_organisation(array &$variables) {
|
||||||
// Fetch OCOrganisation Entity Object.
|
_template_preprocess_entity($variables);
|
||||||
$oc_organisation = $variables['elements']['#oc_organisation'];
|
|
||||||
|
|
||||||
// Helpful $content variable for templates.
|
|
||||||
foreach (Element::children($variables['elements']) as $key) {
|
|
||||||
$variables['content'][$key] = $variables['elements'][$key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
#}
|
#}
|
||||||
<div{{ attributes.addClass('oc_organisation') }}>
|
<div{{ attributes.addClass('oc_organisation') }}>
|
||||||
{% if content %}
|
{% if normal_fields %}
|
||||||
{{- content -}}
|
<div id='static_data'>{{- normal_fields -}}</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if extra_fields %}
|
||||||
|
<div id='dynamic_data'>{{- extra_fields -}}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
* Contains opencase.module.
|
* Contains opencase.module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Drupal\Core\Routing\RouteMatchInterface;
|
use Drupal\Core\Render\Element;
|
||||||
use Drupal\Core\Access\AccessResult;
|
use Drupal\Core\Access\AccessResult;
|
||||||
|
use Drupal\Core\Routing\RouteMatchInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_element_info_alter().
|
* Implements hook_element_info_alter().
|
||||||
@ -14,6 +15,18 @@ function opencase_element_info_alter(array &$types) {
|
|||||||
$types['datetime']['#process'][] = 'opencase_process_element';
|
$types['datetime']['#process'][] = 'opencase_process_element';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _template_preprocess_entity(&$variables) {
|
||||||
|
foreach (Element::children($variables['elements']) as $key) {
|
||||||
|
if (is_extra_field($variables['elements'][$key])) {
|
||||||
|
$variables['extra_fields'][$key] = $variables['elements'][$key];
|
||||||
|
} else {
|
||||||
|
$variables['normal_fields'][$key] = $variables['elements'][$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function is_extra_field($element){
|
||||||
|
return array_key_exists('#field', $element);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element process callback for datetime fields. Removes the seconds part.
|
* Element process callback for datetime fields. Removes the seconds part.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?php declare(strict_types = 1);
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
namespace Drupal\opencase;
|
namespace Drupal\opencase;
|
||||||
use Drupal;
|
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\opencase\Utils;
|
use Drupal\opencase\Utils;
|
||||||
|
|
||||||
@ -9,9 +8,10 @@ final class TimeBasedFieldUpdater {
|
|||||||
|
|
||||||
private EntityTypeManagerInterface $entityTypeManager;
|
private EntityTypeManagerInterface $entityTypeManager;
|
||||||
private string $date_field;
|
private string $date_field;
|
||||||
|
private Utils $utils;
|
||||||
private string $entity_type;
|
private string $entity_type;
|
||||||
private array $conditions;
|
|
||||||
private string $date_format;
|
private string $date_format;
|
||||||
|
private string $bundle;
|
||||||
|
|
||||||
final public function __construct(
|
final public function __construct(
|
||||||
EntityTypeManagerInterface $entityTypeManager,
|
EntityTypeManagerInterface $entityTypeManager,
|
||||||
@ -33,11 +33,14 @@ final class TimeBasedFieldUpdater {
|
|||||||
$conditions[] = ['type', $this->bundle, '='];
|
$conditions[] = ['type', $this->bundle, '='];
|
||||||
$this->utils->addConditionsToQuery($query, $conditions);
|
$this->utils->addConditionsToQuery($query, $conditions);
|
||||||
foreach($query->execute() as $id) {
|
foreach($query->execute() as $id) {
|
||||||
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($id);
|
$this->updateEntity($id, $new_values);
|
||||||
foreach($new_values as $new_field=>$new_value) {
|
|
||||||
$entity->$new_field = $new_value;
|
|
||||||
}
|
|
||||||
$entity->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private function updateEntity(int $entity_id, array $new_values): void {
|
||||||
|
$entity = $this->entityTypeManager->getStorage($this->entity_type)->load($entity_id);
|
||||||
|
foreach($new_values as $new_field=>$new_value) {
|
||||||
|
$entity->$new_field = $new_value;
|
||||||
|
}
|
||||||
|
$entity->save();
|
||||||
|
}
|
||||||
}
|
}
|
@ -50,4 +50,4 @@ class Utils {
|
|||||||
$term = reset($terms);
|
$term = reset($terms);
|
||||||
return (int)(!empty($term) ? $term->id() : 0);
|
return (int)(!empty($term) ? $term->id() : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user