completed computed field_reference dev
This commit is contained in:
parent
75b908ba26
commit
d9e494e6db
|
@ -46,6 +46,7 @@
|
||||||
"drupal/migrate_plus": "4.x-dev",
|
"drupal/migrate_plus": "4.x-dev",
|
||||||
"drupal/migrate_tools": "4.x-dev",
|
"drupal/migrate_tools": "4.x-dev",
|
||||||
"drupal/mimemail": "1.x-dev",
|
"drupal/mimemail": "1.x-dev",
|
||||||
|
"drupal/modules_weight": "^1.8",
|
||||||
"drupal/restui": "^1.16",
|
"drupal/restui": "^1.16",
|
||||||
"drupal/search_api_autocomplete": "^1.2",
|
"drupal/search_api_autocomplete": "^1.2",
|
||||||
"drupal/search_api_page": "1.x-dev",
|
"drupal/search_api_page": "1.x-dev",
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "e67674c8f819a51a74785fddb76fb1d5",
|
"content-hash": "7e10b3f48a875330ee707d7cee2bac93",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "alchemy/zippy",
|
"name": "alchemy/zippy",
|
||||||
|
@ -8130,6 +8130,70 @@
|
||||||
},
|
},
|
||||||
"time": "2019-05-08T04:46:52+00:00"
|
"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",
|
"name": "drupal/pagerer",
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
page_alter: false
|
||||||
|
raw_names: false
|
||||||
|
error_handlers:
|
||||||
|
- 0
|
||||||
|
rebuild_theme: true
|
||||||
|
devel_dumper: default
|
|
@ -25,6 +25,7 @@ dependencies:
|
||||||
- image.style.thumbnail
|
- image.style.thumbnail
|
||||||
- node.type.materiau
|
- node.type.materiau
|
||||||
module:
|
module:
|
||||||
|
- computed_field
|
||||||
- cshs
|
- cshs
|
||||||
- field_group
|
- field_group
|
||||||
- file
|
- file
|
||||||
|
@ -90,7 +91,7 @@ third_party_settings:
|
||||||
- field_materiau_images
|
- field_materiau_images
|
||||||
- field_video
|
- field_video
|
||||||
parent_name: group_htabs
|
parent_name: group_htabs
|
||||||
weight: 10
|
weight: 11
|
||||||
format_type: tab
|
format_type: tab
|
||||||
format_settings:
|
format_settings:
|
||||||
id: ''
|
id: ''
|
||||||
|
@ -105,7 +106,7 @@ third_party_settings:
|
||||||
- field_manufacturer
|
- field_manufacturer
|
||||||
- field_distributor
|
- field_distributor
|
||||||
parent_name: group_htabs
|
parent_name: group_htabs
|
||||||
weight: 11
|
weight: 12
|
||||||
format_type: tab
|
format_type: tab
|
||||||
format_settings:
|
format_settings:
|
||||||
id: ''
|
id: ''
|
||||||
|
@ -119,7 +120,7 @@ third_party_settings:
|
||||||
children:
|
children:
|
||||||
- field_attachments
|
- field_attachments
|
||||||
parent_name: group_htabs
|
parent_name: group_htabs
|
||||||
weight: 12
|
weight: 13
|
||||||
format_type: tab
|
format_type: tab
|
||||||
format_settings:
|
format_settings:
|
||||||
id: ''
|
id: ''
|
||||||
|
@ -134,7 +135,7 @@ third_party_settings:
|
||||||
- field_linked_materials
|
- field_linked_materials
|
||||||
- field_linked_articles
|
- field_linked_articles
|
||||||
parent_name: group_htabs
|
parent_name: group_htabs
|
||||||
weight: 13
|
weight: 14
|
||||||
format_type: tab
|
format_type: tab
|
||||||
format_settings:
|
format_settings:
|
||||||
id: ''
|
id: ''
|
||||||
|
@ -148,7 +149,7 @@ third_party_settings:
|
||||||
children:
|
children:
|
||||||
- field_samples
|
- field_samples
|
||||||
parent_name: group_htabs
|
parent_name: group_htabs
|
||||||
weight: 14
|
weight: 15
|
||||||
format_type: tab
|
format_type: tab
|
||||||
format_settings:
|
format_settings:
|
||||||
id: ''
|
id: ''
|
||||||
|
@ -170,7 +171,6 @@ third_party_settings:
|
||||||
weight: 1
|
weight: 1
|
||||||
format_type: tab
|
format_type: tab
|
||||||
format_settings:
|
format_settings:
|
||||||
label: Internal
|
|
||||||
formatter: open
|
formatter: open
|
||||||
description: ''
|
description: ''
|
||||||
required_fields: true
|
required_fields: true
|
||||||
|
@ -200,7 +200,7 @@ content:
|
||||||
type: file_generic
|
type: file_generic
|
||||||
region: content
|
region: content
|
||||||
field_distributor:
|
field_distributor:
|
||||||
weight: 16
|
weight: 17
|
||||||
settings:
|
settings:
|
||||||
match_operator: CONTAINS
|
match_operator: CONTAINS
|
||||||
size: 60
|
size: 60
|
||||||
|
@ -209,7 +209,7 @@ content:
|
||||||
type: entity_reference_autocomplete
|
type: entity_reference_autocomplete
|
||||||
region: content
|
region: content
|
||||||
field_famille:
|
field_famille:
|
||||||
weight: 26
|
weight: 17
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
type: options_select
|
type: options_select
|
||||||
|
@ -250,7 +250,7 @@ content:
|
||||||
type: image_image
|
type: image_image
|
||||||
region: content
|
region: content
|
||||||
field_memo:
|
field_memo:
|
||||||
weight: 31
|
weight: 20
|
||||||
settings:
|
settings:
|
||||||
rows: 5
|
rows: 5
|
||||||
placeholder: ''
|
placeholder: ''
|
||||||
|
@ -258,11 +258,17 @@ content:
|
||||||
type: string_textarea
|
type: string_textarea
|
||||||
region: content
|
region: content
|
||||||
field_migration:
|
field_migration:
|
||||||
weight: 33
|
weight: 22
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
type: workflow_default
|
type: workflow_default
|
||||||
region: content
|
region: content
|
||||||
|
field_reference:
|
||||||
|
type: computed_string_widget
|
||||||
|
weight: 4
|
||||||
|
region: content
|
||||||
|
settings: { }
|
||||||
|
third_party_settings: { }
|
||||||
field_samples:
|
field_samples:
|
||||||
weight: 34
|
weight: 34
|
||||||
settings: { }
|
settings: { }
|
||||||
|
@ -302,14 +308,14 @@ content:
|
||||||
type: video_embed_field_textfield
|
type: video_embed_field_textfield
|
||||||
region: content
|
region: content
|
||||||
field_workflow:
|
field_workflow:
|
||||||
weight: 32
|
weight: 21
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
type: workflow_default
|
type: workflow_default
|
||||||
region: content
|
region: content
|
||||||
langcode:
|
langcode:
|
||||||
type: language_select
|
type: language_select
|
||||||
weight: 29
|
weight: 18
|
||||||
region: content
|
region: content
|
||||||
settings:
|
settings:
|
||||||
include_locked: true
|
include_locked: true
|
||||||
|
@ -329,7 +335,7 @@ content:
|
||||||
placeholder: ''
|
placeholder: ''
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
translation:
|
translation:
|
||||||
weight: 30
|
weight: 19
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
|
@ -342,7 +348,6 @@ hidden:
|
||||||
created: true
|
created: true
|
||||||
field_index: true
|
field_index: true
|
||||||
field_localisation_old: true
|
field_localisation_old: true
|
||||||
field_reference: true
|
|
||||||
promote: true
|
promote: true
|
||||||
status: true
|
status: true
|
||||||
sticky: true
|
sticky: true
|
||||||
|
|
|
@ -91,7 +91,6 @@ module:
|
||||||
maillog: 0
|
maillog: 0
|
||||||
mailsystem: 0
|
mailsystem: 0
|
||||||
materio_home: 0
|
materio_home: 0
|
||||||
materio_id: 0
|
|
||||||
materio_jsonapi: 0
|
materio_jsonapi: 0
|
||||||
materio_migrate: 0
|
materio_migrate: 0
|
||||||
materio_samples: 0
|
materio_samples: 0
|
||||||
|
@ -107,6 +106,7 @@ module:
|
||||||
migrate_plus: 0
|
migrate_plus: 0
|
||||||
migrate_tools: 0
|
migrate_tools: 0
|
||||||
mimemail: 0
|
mimemail: 0
|
||||||
|
modules_weight: 0
|
||||||
node: 0
|
node: 0
|
||||||
options: 0
|
options: 0
|
||||||
page_cache: 0
|
page_cache: 0
|
||||||
|
@ -164,6 +164,7 @@ module:
|
||||||
pathauto: 1
|
pathauto: 1
|
||||||
content_translation: 10
|
content_translation: 10
|
||||||
views: 10
|
views: 10
|
||||||
|
materio_id: 11
|
||||||
figli_starter_kit: 1000
|
figli_starter_kit: 1000
|
||||||
theme:
|
theme:
|
||||||
stable: 0
|
stable: 0
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
show_system_modules: true
|
||||||
|
_core:
|
||||||
|
default_config_hash: IMfcudoEwt2voUZwyBZA8OhzYCIGxe94CylyRFodjxc
|
|
@ -2,62 +2,36 @@
|
||||||
|
|
||||||
|
|
||||||
function computed_field_field_index_compute($entity_type_manager, $entity, $fields, $delta){
|
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
|
if (!empty($entity->field_index->value)) { // the node is not new
|
||||||
return $entity->field_index->value;
|
return $entity->field_index->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: finish the job
|
// the node is new
|
||||||
/* FROM D7
|
// get all same entities in same family
|
||||||
|
$query = \Drupal::entityQuery($entity->getEntityTypeId())
|
||||||
// dsm('-- computed --');
|
->condition('type', $entity->bundle())
|
||||||
// dsm($entity_field, '$entity_field');
|
->condition('field_famille', $famille)
|
||||||
// dsm($entity_type, '$entity_type');
|
->sort('field_index', 'DESC')
|
||||||
// dsm($entity, '$entity');
|
->range(0,1);
|
||||||
// dsm($field, '$field');
|
|
||||||
// dsm($instance, '$instance');
|
$nids = $query->execute();
|
||||||
// dsm($items, '$items');
|
|
||||||
|
if(is_array($nids)){
|
||||||
// dsm($entity_field[0]['value'], 'entity_field value');
|
$last = entity_load($entity->getEntityTypeId(), array_pop($nids));
|
||||||
|
// get identifiants fo these entities
|
||||||
if (!empty($entity_field[0]['value'])) { // the node is not new
|
$index = $last->get('field_index')->getValue()[0]['value'] + 1;
|
||||||
|
}else{
|
||||||
return $entity_field[0]['value'];
|
$index = '1';
|
||||||
}
|
}
|
||||||
else { // the node is new
|
return $index;
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
if (!empty($entity->field_reference->value)) { // the node is not new
|
||||||
return $entity->field_reference->value;
|
return $entity->field_reference->value;
|
||||||
}
|
}
|
||||||
|
// the node is new
|
||||||
// TODO: finish the job
|
// parse the value to a string as 0023 or 4458 or 0001
|
||||||
/* FROM D7
|
$index_parts = str_split($entity->field_index->value);
|
||||||
|
while (count($index_parts) < 4) {
|
||||||
// dsm('-- computed --');
|
array_unshift($index_parts, "0");
|
||||||
// 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'];
|
|
||||||
}
|
}
|
||||||
else { // the node is new
|
return $entity->field_famille->value.'-'.implode('', $index_parts);
|
||||||
$entity_field[0]['value'] = $entity->field_famille['und'][0]['value'].'-'.$entity->field_identifiant['und'][0]['value'];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function computed_field_field_reference_materio_display($field, $entity_field_item, $entity_lang = "en", $langcode = "en") {
|
// function computed_field_field_reference_materio_display($field, $entity_field_item, $entity_lang = "en", $langcode = "en") {
|
||||||
// return $entity_field_item['value'];
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue