PHP code example of gertvdb / entity_field_helper

1. Go to this page and download the library: Download gertvdb/entity_field_helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gertvdb / entity_field_helper example snippets

 
  /** @var \Drupal\entity_field_helper\Plugin\EntityFieldHelperManager $pluginManager */
  $pluginManager = \Drupal::service('plugin.manager.entity_field_helper');
  
  // Get the node object.
  $node = Node::load(1);
  
  $imageHelper = $pluginManager->imageHelper();
  $visuals = $imageHelper->getValues($node, 'field_visuals');
  
  $images = [];
  $imageStyle = ImageStyle::load('slider');
  
  foreach ($visuals as $visual) {
      $image = $imageHelper->getImage($visual);
      $imageWidth = $image->getWidth();
      if ($imageWidth > 1000) {
        $images[] = $imageHelper->getImageStyleUrl($visual, $imageStyle);
      }
  }