Comments (20)
$entityinfo now contains the mentioned properties as described above:
- study_emikat_id
- study_datapackage_uuid
- study_area
(If a value has not yet been set for the study, the field contains null
)
from csis-helpers-module.
As requested here, $entityinfo now contains a eea_city_field
entry with the EEA city name (null if no city has been yet selected in the study).
from csis-helpers-module.
Ah I misunderstood you, sorry. So you want to use the entity info for other than gl-step nodes?
For this function csis_helpers_node_entity_info
has to be modified.
First step is to determine which node type we have: change the current code of the function to
$type = $entity->bundle()
switch ( $type) {
case 'gl_step':
/*the code of the current function here*/
case: 'node_type'
}
In the case part fort the data package node type you can then query the fields of the data package by using $variable = $datapackageNode->get('field_machine_name')
as I described above.
For resources you have query the data packagee the resource belongs first. This works like this::
$query = \Drupal::entityQuery('node')
->condition('type', 'data_package'),
->condition('field_resources', $entity->id());
$nids = $query->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
Doing so throws some questions: What if the resource is in more than one datapackage? how to know which one is the correct data package?.
After you have done this you will have to modify
function csis_helpers_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode){
if ($entity->bundle() == "gl_step" && $view_mode != "compact") {
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_node_entity_info($entity);
$build['#attached']['library'][] = 'csis_helpers/entityinfo_helpers';
$build['#attached']['library'][] = 'csis_helpers/include_in_report';
$build['#attached']['library'][] = 'csis_helpers/html2canvas';
$build['#attached']['library'][] = 'csis_helpers/seamless';
$build['#attached']['library'][] = 'csis_helpers/update_step_relations';
}
}
Add a
if($entity->bundle() == "content type" ){}
Block for each content type and set in this
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_node_entity_info($entity);
When do need this infos? Only if the data package is viewed? I ask because in current design, if you view a page with Study/Step and Datapackage the entitity info will only show the info from one of them. The one which is rendered last.
To circumvent this we will have to change
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_node_entity_info($entity);
to something like
$build['#attached']['drupalSettings']['csisHelpers']['someotherkey'] = csis_helpers_node_entity_info($entity);
from csis-helpers-module.
Splitting is what I wanted to suggest.
The field spatial extend is an entity reference field so we need the entity which is referenced and get the wanted field value from it.
$spatial_extends = $entity->get('field_spatial_extent')->referencedEntities(); // referencedEntities() returns an array of entities
$spatial_extend = $spatial_extend[0]->get('fieldname')->value;
from csis-helpers-module.
csis_entity_info.js needs to be updated, too. What's the purpose of this script? Where is it used?
I was wondering about that myself. That's a question to @fgeyer16, do we even need this anymore?
@p-a-s-c-a-l :
regarding debugging the content of entites in Drupal I usually use dump($variable)
(first you have to select the "Symfony var-dumper" option in the Devel settings (.../admin/config/development/devel) of your local instance).
So for example to check the content of the $spatial_extends it would look like this:
dump($spatial_extends);
and on the website it would then look something like this:
From that I learned that for the spatial extend the fields have different names than what @fgeyer16 wrote above. To extract the values, the code should look like this:
$spatialExtent = array(
'minx' => $spatial_extends[0]->get('field_xmin')->value,
'miny' => $spatial_extends[0]->get('field_ymin')->value,
'maxx' => $spatial_extends[0]->get('field_xmax')->value,
'maxy' => $spatial_extends[0]->get('field_ymax')->value,
);
In addition I deactivated all your console_log
function calls and then it seemed to work just fine for your latest commit and viewing this data package.
Checking the drupal-settings in the html document for above data package, I found:
"datapackageInfo":
- id
- uuid
- write_permissions
- name
- minx
- miny
- maxx
- maxy
Something to keep in mind:
Since on that data package page all included resources are shown as "rendered entities", the resourceInfo
is also called for each of those resources, however only one makes it into the drupal-settings, since they get overwritten each time. idk if you need the resourceInfo
when viewing the data pacakge or not, but this is something we should keep in mind.
from csis-helpers-module.
@fgeyer16 No, finally I've managed implemented all changes I need in https://github.com/clarity-h2020/csis-helpers-module/tree/feature/010-extend-entityinfo, now testing with iFrame Map Components. If this work's I'll merge the branch in DEV. So ATM no action from your side needed. Thanks!
from csis-helpers-module.
In order to support this feature, we need additional properties in $entityinfo
which relate to fields in Data Package and Resource node types, e.g. uuid
and field_bounding_box
of data_package
.
I noticed there are two methods in csis_helpers.module which apparently do the same:
function csis_helpers_node_entity_info(\Drupal\Core\Entity\EntityInterface $entity)
and
function csis_helpers_group_entity_info(\Drupal\Core\Entity\EntityInterface $entity)
. Why?
I want to extend csis_helpers_node_entity_info
. How can I access e.g. the data_package
node and extract the required fields?
from csis-helpers-module.
They do the same because we need it once done for a node entity and once for a group entity as the source of the data. Since the way how to get the data is different for node and group we have to do it twice in slightly different ways.
As far as I can see the the data package uuid is already included in the entityinfo.
"csisHelpers": {
"entityinfo": {
"step": null,
"step_uuid": null,
"study": "17",
"study_uuid": "40e0c559-a1e6-4724-af66-bf2df1f3d7ee",
"study_emikat_id": "3179",
"study_datapackage_uuid": "2434ce93-93d4-4ca2-8618-a2de768d3f16",
"study_area": "POLYGON ((14.133408 40.838424, 14.133408 40.897965, 14.243305 40.897965, 14.243305 40.838424, 14.133408 40.838424))",
"eea_city_name": "Napoli",
"write_permissions": 1
}
},
So you could load the data package by REST API and extract the properties then. If you want to have the properties direct in the entity info you can extract them in the module in the
if ($groupDatapackageID) {
// load the datapackage selecteds by the study
$datapackageNode = \Drupal\node\Entity\Node::load($groupDatapackageID);
$datapackageUUID = $datapackageNode->uuid();
}
blocks in the functions you mentioned (don't forget to do it in both) and then add the value to the
$entityinfo = array(
'step'=> null,
'step_uuid' => null,
'study'=> $entity->id(),
'study_uuid'=> $entity->uuid(),
'study_emikat_id' => $entity->get('field_emikat_id')->value,
'study_datapackage_uuid' => $datapackageUUID,
'study_area' => $entity->get('field_area')->value,
'eea_city_name' => $eeaName,
'write_permissions' => ($has_user_special_roles ? 0 : 1)
);
array.
Extracting the value might be tricky. Always the same will be the beginning with
$variable = $datapackageNode->get('field_machine_name')
for entity reference fields you will have to do $variable = $datapackageNode->get('field_machine_name')->target_id
for other fields it is most likley $variable = $datapackageNode->get('field_machine_name')->value
. If this does not give you the right values please make a kint($datapackageNode->get('field_machine_name'))
and refresh a page (best do a cache clear) on which you need the info. This will print out the structure of the field in a nice good readable mode. Sometimes the Site is broken after printing out the debug info since this can be send before the html header. SO do not be concerned if this happens. The page will work as designed if you remove the line.
from csis-helpers-module.
@fgeyer16 In the views I'm talking about, there is not study (group), so study_datapackage_uuid which is derived from field_data_package
of the study group type is not available at all. E.g. on this page, how do I get the uuid of the datapackage?
from csis-helpers-module.
Ok, thanks. I'll give it a try.
What if the resource is in more than one datapackage?
No that's not problem. In Data Package Nodes, I'm only interested in the data package uuid, in resource nodes, only the resource uuid.
from csis-helpers-module.
if you view a page with Study/Step and Datapackage the entitity info will only show the info from one of them. The one which is rendered last.
That's a problem. E.g. for this Data Package, $entityInfo
seems the become "polluted" with information from a study the data package is assigned to. That means, from the information available in $entityInfo
I cannot determine whether the page shown is a study, data package or a resource. :-(
from csis-helpers-module.
I've spilt entityinfo in studyInfo, datapackageInfo and resourceInfo in /feature/010-extend-entityinfo. entityInfo should no longer be used.
BTW, spatial_extent' => $entity->get('field_spatial_extent')->value
returns null for datapackage and resource even if a spatial extent is set.
from csis-helpers-module.
Splitting is what I wanted to suggest.
Unfortunately, this doesn't work. studyInfo, datapackageInfo and resourceInfo, etc, always contain all properties of all entity types. I have the impression, that $entityinfo;
is defined as global variable.
$spatial_extends = $entity->get('field_spatial_extent')->referencedEntities();
if(!empty($spatial_extends) && is_array($spatial_extends) && sizeof($spatial_extends) > 0)
This returns false
even if field_spatial_extent
is defined. Is there any possibility to debug the module? Printing some log messages may work, but I would prefer a professional debugger.
from csis-helpers-module.
Now, this statement seems to evaluate to false on the Data Package Node: /node/682
$type = $entity->bundle();
if ($type == ("gl_step" || "data_package" || "data_package_metadata") && $view_mode != "compact") {
from csis-helpers-module.
csis_entity_info.js needs to be updated, too. What's the purpose of this script? Where is it used?
from csis-helpers-module.
csis_entity_info.js needs to be updated, too. What's the purpose of this script? Where is it used?
This was thought to provide helper functions so nobody needs to know where in the drupal settings the entity infos are.If nobody uses this or wants this we can remove this file as well.
Regarding debugging: I use kint($variable). This is function/module provided by the devel module. You need to enable the devel Kint module. @patrickkaleta provides dump also information on available methods for objects?
Since on that data package page all included resources are shown as "rendered entities", the resourceInfo is also called for each of those resources, however only one makes it into the drupal-settings, since they get overwritten each time. idk if you need the resourceInfo when viewing the data pacakge or not, but this is something we should keep in mind.
I'm thinking if there is away to fill the entityinfos only if the node is not rendered because it is referenced by another one.
from csis-helpers-module.
@patrickkaleta provides dump also information on available methods for objects?
No it does not. However, I noticed that kint()
sometimes fails to load an object if it's too big (which sadly is quite often the case for our entities) and then I get just a blank page.
from csis-helpers-module.
I noticed that kint() sometimes fails to load an object if it's too big (which sadly is quite often the case for our entities) and then I get just a blank page.
yes that can happen because if you kint() the "right" variable it will load the page multiple times and then run out of memory especially if somewhere in the variable there is a reference to the(a) (sub)variable which can cause some kind of endless loop I assume.
In web/modules/contrib/devel/kint/kint/config.default.php
you can change the "kint levels". This is how many levels kint will proceed to print out the stuff. Default ist set to 7 but this seems to be to much. In my experience 4 to 5 levels is enough and stops this error to occur. AN if you need to dig depper you will have to do a kint($variable['the']['deeper']['level'])
from csis-helpers-module.
@p-a-s-c-a-l: You wait for me to solve that with the additional infos right? Not that we work on the same thing an may against each other as well ;-)
from csis-helpers-module.
done
from csis-helpers-module.
Related Issues (20)
- Explain what the module does HOT 1
- Emikat Trigger specifications HOT 4
- Include iFrames in Report HOT 17
- Support for additional processing variables HOT 10
- A wrong parameter name is used HOT 2
- Hide edit buttons if user permissions are not sufficient HOT 1
- Calculation in progress/finished indication HOT 7
- Creating automated tests for Integration with Emikat HOT 1
- Transport Module (TM) trigger specifications HOT 5
- Cannot read property 'step' of undefined HOT 1
- Include in Report button: use jpeg instead of png images
- Support for extended iFrame query parameters HOT 1
- Add boolean field for Adaptation Project into $StudyInfo HOT 2
- Documentation HOT 1
- Get Node UUID HOT 2
- 404 Error message for Report image GET request via JSON:API HOT 1
- Theme Missing HOT 1
- Opening Edit-form as modal not working for links created by the module HOT 2
- Include In Report Button not working properly HOT 54
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csis-helpers-module.