Render ds field views
Thu Jan 18 2024 13:38:59 GMT+0000 (Coordinated Universal Time)
Saved by
@saida
<?php
namespace Drupal\irsjg_home\Plugin\DsField;
use Drupal\ds\Plugin\DsField\DsFieldBase;
use \Drupal\views\Views;
// ejemplo irsjg_hom/src/Plugin/videosMasReciente.php
/**
* Provides a custom DsField to display home header as field
*
* @DsField(
* id = "irsjg_home_video_field",
* title = @Translation("IRSJG Home | Video más reciente"),
* entity_type = "node",
* provider = "irsjg_home",
* ui_limit = {"home|full"}
* )
*/
class HomeMasReciente extends DsFieldBase {
/**
* {@inheritdoc}
*/
public function build() {
$view = Views::getView('irsjg_homepage_slicks');
if (!is_object($view)) {
return;
}
$view->setDisplay('block_home_video_slider');
$view->preExecute();
$view->execute();
$view->element['#attached']['library'][] = 'irsjg_home/video_slider';
$content = $view->buildRenderable('block_home_video_slider');
return $content;
}
}
content_copyCOPY
Comments