ActivityAttachments.php in CiviCRM Entity 8.3
File
src/Plugin/views/field/ActivityAttachments.php
View source
<?php
namespace Drupal\civicrm_entity\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\civicrm_entity\CiviCrmApiInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ActivityAttachments extends FieldPluginBase {
protected $civicrmApi;
public function usesGroupBy() {
return FALSE;
}
public function __construct(array $configuration, $plugin_id, array $plugin_definition, CiviCrmApiInterface $civicrm_api) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->civicrmApi = $civicrm_api;
}
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->civicrmApi
->civicrmInitialize();
}
public function render(ResultRow $values) {
$value = $this
->getValue($values);
if ($value) {
$items = [];
foreach (\CRM_Core_BAO_File::getEntityFile('civicrm_activity', $value) as $file) {
$items[] = [
'#type' => 'inline_template',
'#template' => $file['href'],
];
}
return [
'#theme' => 'item_list',
'#items' => $items,
];
}
return NULL;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('civicrm_entity.api'));
}
}