Showing posts with label media fields. Show all posts
Showing posts with label media fields. Show all posts

Thursday 6 September 2018

Media entity fields render in drupal 8 Node Twig template.

If we want to load media entity fields on node twig template. It's easy to load media entity, Please have a look..

{# call to media entity fields on node twig #}

{% for key, item in node.field_document_entity_browser %} 
// This is the node field which is connect to media field `field_document_entity_browser`..
{% if node.field_document_entity_browser[key].entity %}
// here we are rendering media entity field which machine name is `field_capt2120`..                           
{{ node.field_document_entity_browser.entity.field_capt2120[key].value }}

// here we are rendering media entity image field which machine name is `field_media_image`..        
{%if item.entity %}
{% set media = item.entity %}
{% set file = media.field_media_image.entity %}
{% set uri = file_url(file.uri.value) %}
                              
<img src="{{ uri }}" alt="{{ media.name.value }}" />
                          
 {% endif %}                           
                                                                                     
 {% endif %}
  {% endfor %}



Note: If have any suggestions or issue regarding 'Media entity fields render in drupal 8 Node Twig template.' then you can ask by comments.  

Tuesday 4 September 2018

Programmatically Media load in drupal 8.

If we want to load Media entity. we have to add library on the top of page. ( use Drupal\media\Entity\Media; )
Then its easy to load media entity by the syntax.
   
Syntax:
$media_detail = Media::load($mid);    // here $mid is media entity id       
   
now if we want to get image field data of media field then syntax is..

$media_img = file_create_url($media_detail->field_media_image->entity->getFileUri());
 // here field_media_image is field name in media entity
   
now if we want to get any text field value then syntax will be..

$media_caption = $media_detail->get('field_capt2120')->getValue();   
// here field_capt2120 is the machine name of caption field in media entity    

foreach($m_caption as $mkey){
   $capval = $mkey['value'];    // here we will get the caption value           
}


Note: If have any suggestions or issue regarding 'Programmatically Media load in drupal 8.' then you can ask by comments.   

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...