completed computed field_reference dev

This commit is contained in:
Bachir Soussi Chiadmi 2019-06-22 19:34:21 +02:00
parent 75b908ba26
commit d9e494e6db
7 changed files with 145 additions and 85 deletions

View File

@ -46,6 +46,7 @@
"drupal/migrate_plus": "4.x-dev",
"drupal/migrate_tools": "4.x-dev",
"drupal/mimemail": "1.x-dev",
"drupal/modules_weight": "^1.8",
"drupal/restui": "^1.16",
"drupal/search_api_autocomplete": "^1.2",
"drupal/search_api_page": "1.x-dev",

66
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e67674c8f819a51a74785fddb76fb1d5",
"content-hash": "7e10b3f48a875330ee707d7cee2bac93",
"packages": [
{
"name": "alchemy/zippy",
@ -8130,6 +8130,70 @@
},
"time": "2019-05-08T04:46:52+00:00"
},
{
"name": "drupal/modules_weight",
"version": "1.8.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/modules_weight.git",
"reference": "8.x-1.8"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/modules_weight-8.x-1.8.zip",
"reference": "8.x-1.8",
"shasum": "6861c4def64d489fda24ce6a1914ea970ccb7143"
},
"require": {
"drupal/core": "~8.6"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.8",
"datestamp": "1557514985",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "Adrian Cid Almaguer (adriancid)",
"homepage": "https://www.drupal.org/u/adriancid",
"email": "adriancid@gmail.com",
"role": "Maintainer"
},
{
"name": "Ma'moun Othman (artofeclipse)",
"homepage": "https://www.drupal.org/u/artofeclipse",
"role": "Maintainer"
},
{
"name": "josebc",
"homepage": "https://www.drupal.org/user/1376836"
}
],
"description": "Allows to change the modules execution order.",
"homepage": "https://www.drupal.org/project/modules_weight",
"keywords": [
"Drupal",
"Modules",
"Order"
],
"support": {
"source": "http://cgit.drupalcode.org/modules_weight",
"issues": "https://www.drupal.org/project/issues/modules_weight"
}
},
{
"name": "drupal/pagerer",
"version": "1.4.0",

View File

@ -0,0 +1,6 @@
page_alter: false
raw_names: false
error_handlers:
- 0
rebuild_theme: true
devel_dumper: default

View File

@ -25,6 +25,7 @@ dependencies:
- image.style.thumbnail
- node.type.materiau
module:
- computed_field
- cshs
- field_group
- file
@ -90,7 +91,7 @@ third_party_settings:
- field_materiau_images
- field_video
parent_name: group_htabs
weight: 10
weight: 11
format_type: tab
format_settings:
id: ''
@ -105,7 +106,7 @@ third_party_settings:
- field_manufacturer
- field_distributor
parent_name: group_htabs
weight: 11
weight: 12
format_type: tab
format_settings:
id: ''
@ -119,7 +120,7 @@ third_party_settings:
children:
- field_attachments
parent_name: group_htabs
weight: 12
weight: 13
format_type: tab
format_settings:
id: ''
@ -134,7 +135,7 @@ third_party_settings:
- field_linked_materials
- field_linked_articles
parent_name: group_htabs
weight: 13
weight: 14
format_type: tab
format_settings:
id: ''
@ -148,7 +149,7 @@ third_party_settings:
children:
- field_samples
parent_name: group_htabs
weight: 14
weight: 15
format_type: tab
format_settings:
id: ''
@ -170,7 +171,6 @@ third_party_settings:
weight: 1
format_type: tab
format_settings:
label: Internal
formatter: open
description: ''
required_fields: true
@ -200,7 +200,7 @@ content:
type: file_generic
region: content
field_distributor:
weight: 16
weight: 17
settings:
match_operator: CONTAINS
size: 60
@ -209,7 +209,7 @@ content:
type: entity_reference_autocomplete
region: content
field_famille:
weight: 26
weight: 17
settings: { }
third_party_settings: { }
type: options_select
@ -250,7 +250,7 @@ content:
type: image_image
region: content
field_memo:
weight: 31
weight: 20
settings:
rows: 5
placeholder: ''
@ -258,11 +258,17 @@ content:
type: string_textarea
region: content
field_migration:
weight: 33
weight: 22
settings: { }
third_party_settings: { }
type: workflow_default
region: content
field_reference:
type: computed_string_widget
weight: 4
region: content
settings: { }
third_party_settings: { }
field_samples:
weight: 34
settings: { }
@ -302,14 +308,14 @@ content:
type: video_embed_field_textfield
region: content
field_workflow:
weight: 32
weight: 21
settings: { }
third_party_settings: { }
type: workflow_default
region: content
langcode:
type: language_select
weight: 29
weight: 18
region: content
settings:
include_locked: true
@ -329,7 +335,7 @@ content:
placeholder: ''
third_party_settings: { }
translation:
weight: 30
weight: 19
region: content
settings: { }
third_party_settings: { }
@ -342,7 +348,6 @@ hidden:
created: true
field_index: true
field_localisation_old: true
field_reference: true
promote: true
status: true
sticky: true

View File

@ -91,7 +91,6 @@ module:
maillog: 0
mailsystem: 0
materio_home: 0
materio_id: 0
materio_jsonapi: 0
materio_migrate: 0
materio_samples: 0
@ -107,6 +106,7 @@ module:
migrate_plus: 0
migrate_tools: 0
mimemail: 0
modules_weight: 0
node: 0
options: 0
page_cache: 0
@ -164,6 +164,7 @@ module:
pathauto: 1
content_translation: 10
views: 10
materio_id: 11
figli_starter_kit: 1000
theme:
stable: 0

View File

@ -0,0 +1,3 @@
show_system_modules: true
_core:
default_config_hash: IMfcudoEwt2voUZwyBZA8OhzYCIGxe94CylyRFodjxc

View File

@ -2,62 +2,36 @@
function computed_field_field_index_compute($entity_type_manager, $entity, $fields, $delta){
// drush_print($entity->field_index->value);
// ksm($entity_type_manager);
// ksm($entity);
// ksm($fields);
// ksm($delta);
$famille = $entity->get('field_famille')->getValue()[0]['value'];
// $entity->isNew(); ??
// TODO: what if familly change ?
if (!empty($entity->field_index->value)) { // the node is not new
return $entity->field_index->value;
}
// TODO: finish the job
/* FROM D7
// the node is new
// get all same entities in same family
$query = \Drupal::entityQuery($entity->getEntityTypeId())
->condition('type', $entity->bundle())
->condition('field_famille', $famille)
->sort('field_index', 'DESC')
->range(0,1);
// dsm('-- computed --');
// dsm($entity_field, '$entity_field');
// dsm($entity_type, '$entity_type');
// dsm($entity, '$entity');
// dsm($field, '$field');
// dsm($instance, '$instance');
// dsm($items, '$items');
$nids = $query->execute();
// dsm($entity_field[0]['value'], 'entity_field value');
if (!empty($entity_field[0]['value'])) { // the node is not new
return $entity_field[0]['value'];
if(is_array($nids)){
$last = entity_load($entity->getEntityTypeId(), array_pop($nids));
// get identifiants fo these entities
$index = $last->get('field_index')->getValue()[0]['value'] + 1;
}else{
$index = '1';
}
else { // the node is new
// get all same entities in same family
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', $entity->type)
->fieldCondition('field_famille', 'value', $entity->field_famille['und'][0]['value']);
$result = $query->execute();
if(is_array($result[$entity_type])){
$entities = entity_load($entity_type, array_keys($result[$entity_type]));
// get identifiants fo these entities
$ids = array();
foreach ($entities as $id => $e) {
$identifiant = field_view_field($entity_type, $e, 'field_identifiant');
$ids[] = $identifiant[0]['#markup'] ? intval($identifiant[0]['#markup']) : 0;
}
sort($ids);
$value = strval(array_pop($ids) + 1);
}else{
$value = '1';
}
// parse the value to a string as 0023 or 4458 or 0001
$value_parts = str_split($value);
while (count($value_parts) < 4) {
array_unshift($value_parts, "0");
}
// record the result
$entity_field[0]['value'] = implode('', $value_parts);
}
*/
return $index;
}
@ -69,26 +43,32 @@ function computed_field_field_reference_compute($entity_type_manager, $entity, $
if (!empty($entity->field_reference->value)) { // the node is not new
return $entity->field_reference->value;
}
// TODO: finish the job
/* FROM D7
// dsm('-- computed --');
// dsm($entity_field, '$entity_field');
// dsm($entity_type, '$entity_type');
// dsm($entity, '$entity');
// dsm($field, '$field');
// dsm($instance, '$instance');
// dsm($items, '$items');
if (!empty($entity_field[0]['value'])) { // the node is not new
return $entity_field[0]['value'];
// the node is new
// parse the value to a string as 0023 or 4458 or 0001
$index_parts = str_split($entity->field_index->value);
while (count($index_parts) < 4) {
array_unshift($index_parts, "0");
}
else { // the node is new
$entity_field[0]['value'] = $entity->field_famille['und'][0]['value'].'-'.$entity->field_identifiant['und'][0]['value'];
}
*/
return $entity->field_famille->value.'-'.implode('', $index_parts);
}
// function computed_field_field_reference_materio_display($field, $entity_field_item, $entity_lang = "en", $langcode = "en") {
// return $entity_field_item['value'];
// }
/**
* Implements hook_form_alter().
*/
function materio_id_form_node_materiau_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// dsm($form_id);
$node = $form_state->getFormObject()->getEntity();
$ref = $node->field_reference->value;
// dsm($ref);
if($ref != ''){
$string = $form['#title']->getUntranslatedString() . ' (@ref)';
// dsm($string);
$args = $form['#title']->getArguments() + array('@ref'=>$ref);
// ksm($args);
$form['#title'] = t($string, $args);
}
}