Remove item from associative array using twig template engine - symfony

I'd like to remove an item form associative array within twig page.
Knowing that I have already the key of the item such as "key1"

Related

Render specific field collection fields in twig template

I have a field collection named, "field_client_scroll" which has multiple fields, two text and an entity reference field to a media image named "field_thumbnail_client". For the text fields I can print their value using
{{ item.content['#field_collection_item'].field_title_client.value }}
I tried to use the following, but with no results
{{ item.content['#field_collection_item'].field_thumbnail_client.value }}
I would like to know what I need to use to print the image or the url to the image using the field collection field.

Drupal select list key in template file

How would I go about getting the key of a select list field in a view template (Row style output)?
The field is added to my view and hidden from display. It contains stuff like:
red|Red
green|Green
blue|Blue
How can I get the selected key (ie. red) for the field in the template?
I was able to print it using:
$view->field['field_color']->view->result[0]->field_field_color[0]['raw']['value']
but I wonder if there is an easier way to get that key.
Thanks in advance.
$row->field_field_color[0]['raw']['value'];

collective.listingviews:how to use custom fields to display dexterity based image field and richtext field

I'd like to use the collective.listingviews controlpanel to display an image and richtext field. I have the image field working but would like to know if there is a simpler way to retrieve the image. When I try to retrieve the richtext field I end up with a permissions error.
The details:
I have a custom dexterity content type (examplecontent) and a collection which retrieves these examplecontent types.
To display the content types I've created a custom 'listingview' for the collection, the goal is that for each retrieved item the following should be displayed:
A RichText Field named 'body'
An Image Field named 'screenshot'
This is a mockup of how the layout might behave:
To retrieve the image field I'm using the custom tal expression:
python:"<img src='%s/view/++widget++form.widgets.screenshot/##download' />" % item.getObject().absolute_url()
To retrieve the body field I'm using the custom tal expression:
python:item.getObject().body
The image field is working but the richtext field gives the following:
RichTextValue object. (Did you mean .raw or .output?)
When I change the tal expression for the richtext field to the following:
python:item.getObject().body.output
I then get the following permissions error:
Insufficient Privileges
You do not have sufficient privileges to view this page. If you believe you are receiving this message in error, contact the site administration.
First off, you should change
python:"<img src='%s/view/++widget++form.widgets.screenshot/##download' />" % item.getObject().absolute_url()
to:
python:"<img src='%s/view/++widget++form.widgets.screenshot/##download' />" % item.getURL()
Since this way means you don't have to get the full object. Note the use of the getURL() method.
For the second expression, try something like this:
item/getObject/##text-transform/body
or
python: item.getObject().restrictedTraverse('##text-transform/body')
untested

Entity reference field and dependent dropdown

I have a content type with an entity reference field referencing to a custom entity. I need to use a select box because an autocomplete widget is not suitable in my case. However, I cannot load all the entities at once as selectable values because they are too many (72000+ the form won't even load). So I default the entity reference select box to a limited number of values using a views filter and then hide it by default. Then I use an ajax dependent dropdown to show and populate the entity reference select box with filtered down values (I'm using a module that implements hook_form_alter).
My problem is that the form won't validate because now I can select entity reference values which are not the default ones in the select box. So I guess I should control in some way the validation rules of the entity reference field. Is there an easy way to do this? Which hook should I use?
Set the entity reference field to autocomplete and take it out of the process entirely in your form alter with $form['field_entity_ref']['#access'] = FALSE. This should fix the validation problem. (of course, "field_entity_ref" is what I'm calling your actual reference field.
Add your own validation to the form, if that is still necessary.
Finally, implement hook_node_presave() to manually put the value of your custom ajax drop down box.
So if your custom ajax select box was named my_custom_ref, then it would look something like this:
function mymodule_node_presave($node) {
if (isset($node->my_custom_ref)) {
$node->field_entity_ref[$node->language][0]['target_id'] = $node->my_custom_ref;
}
}

Loop through child items and get image field for showing on parent's view/template

I have a parent content type RetailFont, it has child types, and one is called FontWeight.
Fontweight has an image field called WeightImage.
I have successfully added a new view and template for RetailFont (called FontWeightView). I would like to loop through and show some of the fields for all the WeightImage items inside it, such as its title and ImageField.
I tried copying folder_summary_view.pt contents to my template file but it generates errors.
Does it need something in my FontWeightView.py file to work? http://www.pastie.org/3286449
test() is a deprecated page template method and should no longer be used.
You can work around this with the logic:
<tal:something condition="python:somecond and ifistrue or ifisfalse" />

Resources