Esempio n. 1
0
 /**
  * Generates an image tag that handle multiple sizes and rendered with picturefill
  *
  * ```
  * $options = [
  *     'sizes' => '(min-width: 40em) 80vw, 100vw'
  *     'srcset' => [375, 480, 780]
  * ]
  * ```
  *
  * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
  * @param array $options picturefill options
  * @return string
  */
 public function picturefill(Entity $entity, array $options)
 {
     $srcset = '';
     foreach ($options['srcset'] as $size) {
         $src = $entity->getUrl(['w' => $size]);
         $src .= " " . $size . "w";
         $srcset[] = $src;
     }
     $options['srcset'] = implode(" ,", $srcset);
     $picturefill = $this->Html->image($entity->getUrl($options), $options);
     $selfLoad = $this->Require->module('picturefill');
     return $picturefill . $selfLoad;
 }