I am having a paragraph with a media entity ref field   &quot;field_paragraph_image_ref&quot;. I would need to modiy the media twig template depending on a field value of the parent, which is a paragraph entity. How can i get the field value from the parent entity in the media preprocess   function hook_preprocess_media__picture__image_without_link(array &amp;$variables) {       $media = $variables['elements']['#media'];       //A method to get the parent entity, that i cannot find in var_dump(get_class_methods($media));       // and finally get a field value from the parent paragraph entity  }
124119
I'm using responsive images (single img tag with srcset and sizes attributes). My content editors can manipulate the displayed size of the image with a custom field on a shared parent entity. Therefore I can't meaningfully use the sizes field from the responsive image module, because my editors can set the image size from 10% of a fixed container up to 100vw on per paragraph level.  I know how to preprocess the sizes attributes, but I don't know how to get to my shared parent entity, which holds the field determining the size of the image's parent container:  function template_preprocess_responsive_image(&amp;$variables) {   // pseudocode: don't know how to this   $imageField = $variables['whatever'];   $parentParagraph = $imageField-&gt;getParentMediaEntity()-&gt;getParentParagraphEntity(); }   My question is how do I get the parent paragraph entity as written above in pseudocode?
24923
I'd like to know when a field from a node it's a paragraph, I only get the type, that it's entity_reference_revisions, I use this method to get the information:  \Drupal\field\Entity\FieldStorageConfig::loadByName()   But I'm not able to get this information   [settings:protected] =&gt; Array     (         [target_type] =&gt; paragraph     )   The only way I get it's to check directly to the database to see it the name of the field it's in the table paragraphs_item_field_data.  Thanks  Oskar
49110
I am writing a template for a views field in Drupal 8. How can I access the raw values of a multi-value field in views? I tried this but it doesn't work.  {% for i in 0.. row.field_color['#items']|length - 1 %} {{ row.field_color[i] }} {% endfor %}
2001
I'm trying to figure how I can get all the values inside an entity reference field  As shown in this image, I have an entity field called Target Participants(field_program_participants) with multiple values.    I have tried to output the values using node.field_program_participants.entity.label, but it only outputs one value.     How can I output all the values inside the field
99190
I have a node object with image field named field_image. When I do  $node   -&gt;get('field_image')   -&gt;first()   -&gt;getValue()   I get array with some properties instead of entity object. The array looks like this:  'target_id' =&gt; string '8' (length=1) 'alt' =&gt; string '' (length=0) 'title' =&gt; string '' (length=0) 'width' =&gt; string '587' (length=3) 'height' =&gt; string '458' (length=3) '_loaded' =&gt; boolean true   '_accessCacheability' =&gt;      object(Drupal\Core\Cache\CacheableMetadata)[1092]       protected 'cacheContexts' =&gt;          array (size=0)           ...       protected 'cacheTags' =&gt;          array (size=0)           ...       protected 'cacheMaxAge' =&gt; int -1   Do I have to manullay load the file entity using target_id or there is a way to automatically get referenced entity object from instance of Drupal\image\Plugin\Field\FieldType\ImageItem?  Why the referenced entity is not accessible via getter? It could be lazy loaded if it's not available immediately.
45685
I'm implementing a node template that uses an image twice; once in a 'normal' way (i.e. using the image style defined in the field's display configuration for that view mode), and the other is as a css background-image property.  I need one of two things:   (ideally) a way to get the URL for a different image style of the same image. a way to get the URL for the image field.   I'm struggling to use dump() and kint() to help myself to an answer. They both output far far too much (thanks to embedded links to "parent" etc.) and seem to not have the info I need. e.g. looking at dump(content.field_image) output the actual URL of the image is not there (so where does it come from such that it can be rendered with {{ content.field_image }}?!). kint() on the other hand dies completely if I pass an argument to it and the top-level version is again far too big to navigate. Debugging was soo much easier with phptemplate + xdebug. (Yes I know it's good that themers can't drop the database.)  There's an answer to (1) that implies , but I don't understand why I can't get the existing URL in (2)?
103862
I am using lightning navigation to pass recordId from parent component to child component.  On button click i am navigating to child component like below url -    I need to get the recordId from URL in child component and pass to apex methods.  I tried the below, but not getting the recordId.    import { LightningElement, api, track, wire } from "lwc";     import { getRecord, generateRecordInputForUpdate } from "lightning/uiRecordApi";     import { CurrentPageReference } from "lightning/navigation";      export default class TestLWC extends LightningElement {      @track getrecordId;       @wire(CurrentPageReference)       currentPageReference;      setCurrentPageReference(currentPageReference) {     this.currentPageReference = currentPageReference;   }       getrecordId =         this.currentPageReference &amp;&amp; this.currentPageReference.state.c__recordId      @wire(getData, { getrecordId: "$getrecordId" })      }
66867
I am trying to modify output in my twig file. In D7, I was able modify data in my array with this  check_markup($tweet-&gt;text, 'full_html');   and I see that this function still exists in D8. However, I'm not sure how I would use this in a filter in twig. This is what I have so far:  {% for tweet in params.tweets %} &lt;div class="tweet-wrapper"&gt; &lt;div class="tweet-profile-image"&gt;     &lt;img src='{{ tweet.user.profile_image_url }}'/&gt; &lt;/div&gt; &lt;div class='tweet-text'&gt;     &lt;!--check_markup($tweet-&gt;text, 'full_html');--&gt;     {{ tweet.text }} &lt;/div&gt;   &lt;/div&gt; {% endfor %}   I actually tried to do this before I sent it to the template as well, but it didn't change anything:   foreach($tweets as $tweet) {   $tweet-&gt;text = check_markup($tweet-&gt;text, 'full_html');   $cleanTweets[] = $tweet; } dpm($tweets); $params = array('tweets' =&gt; $cleanTweets); $tweet_template = array('#theme' =&gt; 'twitter_pull_tweet_listing', '#params' =&gt; $params); return $tweet_template;   What I'm trying to do here is make drupal create links for web links in the twitter tweet text. This worked fine for me in D7.
107826
I have a custom block containing a text field and an image field. I would like to render the block so that the image's URL can be defined as a data attribute of the block's wrapper div so that it can be used by a javascript function to create a parallax background effect behind the text field.  If I make a template file block.parallax.html.twig, I am able to render the image HTML.  {{ content.field_parallax_image.0 }}   However If I try to get the actual image URL, nothing is returned  {{ content.field_parallax_image.0['#url'] }}   If I dump the #item keys  {{ dump(content.field_parallax_image.0['#item']|keys) }}   I am able to get target_id, alt, title, width and height values, but I can't find the URL defined anywhere.  I have also tried to see if I could find anything useful in the block preprocess function but the field_parallax_image #url field in the variables is also empty  function mytheme_preprocess_block(&amp;$variables) {     if( isset($variables['content']['body']['#bundle']) &amp;&amp; $variables['content']['body']['#bundle'] == 'parallax'){         $variables['img_url'] = $variables['elements']['content']['field_parallax_image'][0]['#url'];     } }   Is there a way I can get this URL?
76453
I'm reading a field value and its format from the database. How would I render that value with the format?
117690
I'm really struggling to add a taxonomy_term as an entity reference to a custom entity I've created programmatically.  Here is my configuration based on BaseFieldDefinition (the name of the vocabulary is "specialite":  $fields['speciality_field'] = BaseFieldDefinition::create('entity_reference')   -&gt;setLabel(t('speciality'))   -&gt;setRevisionable(TRUE)   -&gt;setSetting('target_type', 'taxonomy_term')   &gt;setSetting('handler_settings', ['target_bundles' =&gt; ['specialite' =&gt; 'specialite']])   -&gt;setSetting('handler', 'default')   -&gt;setTranslatable(TRUE)   -&gt;setDisplayOptions('view', array(     'label' =&gt; 'hidden',     'type' =&gt; 'author',     'weight' =&gt; 0,   ))   -&gt;setDisplayOptions('form', array(     'type' =&gt; 'entity_reference_autocomplete',     'weight' =&gt; 5,     'settings' =&gt; array(       'match_operator' =&gt; 'CONTAINS',       'size' =&gt; '10',       'autocomplete_type' =&gt; 'tags',       'placeholder' =&gt; '',     ),   ))   -&gt;setDisplayConfigurable('form', TRUE)   -&gt;setDisplayConfigurable('view', TRUE);   This piece of code doesn't work, would you please help to find what I am missing, or redirect me to a good documentation explaining different values for handler_settings  Thank you so much.
47148
I'm trying to create a block that will pass a variable to its template. For now just some text but it will be an array later.  The default block variables such as label are working but I'm unable to get the value to show up in template.  Any ideas ?  FrontAppsBlock.php  namespace Drupal\custom_blocks\Plugin\Block;  use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockPluginInterface; /**  * @Block(  *   id = "front_apps_block",  *   admin_label = @Translation("Front Apps Block"),  * )  */ class FrontAppsBlock extends BlockBase implements BlockPluginInterface {    public function build() {     return array(       '#theme' =&gt; 'front_apps_block',       '#app' =&gt; 'test value',     );   }  }   custom_blocks.module  function custom_blocks_theme($existing, $type, $theme, $path) {   return [     'front_apps_block' =&gt; [       'variables' =&gt; [         'app' =&gt; null       ]     ]   ]; }   block--front-apps-block.html.twig  &lt;p&gt;test: {{ app }}&lt;/p&gt; &lt;p&gt;label: {{ label }}&lt;/p&gt;
79320
For example, my component has the following section that displays a record form:  &lt;template if:true={showRecordForm}&gt;     &lt;lightning-record-form         object-api-name={sObjectApiName}         onsuccess={handleFormSuccess}         record-type-id={recordTypeId}         layout-type="Full"         columns="2"         oncancel={handleFormCancel}         onload={handleFormLoad}&gt;     &lt;/lightning-record-form&gt; &lt;/template&gt;   It will load the form for the object I specify in sObjectApiName, and with the specified record type as well. The problem is that I want to assign some values to specific fields.  Let us say that it is a Case form, and I want to assign an Account ID to the AccountId field, before the case is submitted to the platform.  I tried to query the lightning-input-fields, but with no success:  const inputFields = this.template.querySelectorAll(     'lightning-input-field' ); if (inputFields) {     inputFields.forEach(field =&gt; {         console.log(field)     }); }   This is a snippet from the .  I'm starting to think that this might not be viable, or too much trouble. Is there a way to do this?
42901
I'd like to run a query using the EntityFieldQuery object. I need value from both the node and node_access table therefore I'd need to use INNER JOIN. From the d.o documentation I can't figure out how this is possible.  Here's what I have --  $query = new EntityFieldQuery(); $result = $query-&gt;entityCondition('entity_type', 'node') -&gt;entityCondition('bundle', 'node_access') -&gt;propertyCondition('type', 'external_link') -&gt;propertyCondition('status', 1) -&gt;fieldCondition('gid', '3', '=') -&gt;fieldCondition('realm', 'domain_id', '=') -&gt;fieldCondition('grant_view', '1', '&gt;=') -&gt;range(0,1) -&gt;execute();
1244
I want to be able to echo the URL of the featured image of a post and after looking some on the web I found the following which works fine when I put it in a loop in my front page template.   &lt;?php $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), 'small' ); $urlSmall = $thumbSmall['0']; ?&gt;  &lt;?php echo $urlSmall; ?&gt;   However, want to use variable $urlSmall in other places than in the front page template, and this is where my limited coding skills let me down. I tried to just copy paste  wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), 'small' ); $urlSmall = $thumbSmall['0'];   into my functions.php but that did not work. I need these variables to be globally recognized. What do I do here? write some kind of function?
58950
In views I can add PHP snippets for custom validation or when I want to provide default value for contextual filter. It is telling me that I can use $view or $argument - but where is documentation of these objects? Where can I read what are my possibilities in these areas (or how check this, by using debugger for example)?
2139
In Drupal 7, to get all fields used in a content type, I use the following code. $fields = field_info_instances('node', 'article');  What is the equivalent for Drupal 8?