HierarchyEmbed.php in Entity Reference Hierarchy 8
File
entity_hierarchy_views/src/Plugin/views/display/HierarchyEmbed.php
View source
<?php
namespace Drupal\entity_hierarchy_views\Plugin\views\display;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\Core\Form\FormStateInterface;
class HierarchyEmbed extends DisplayPluginBase {
protected $usesAttachments = TRUE;
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
$categories['entity_hierarchy_embed'] = array(
'title' => t('Embed settings'),
'column' => 'second',
'build' => array(
'#weight' => -10,
),
);
$name = strip_tags($this
->getOption('entity_hierarchy_embed_admin_name'));
if (empty($name)) {
$name = t('None');
}
$options['entity_hierarchy_embed_admin_name'] = array(
'category' => 'entity_hierarchy_embed',
'title' => t('Admin name'),
'value' => views_ui_truncate($name, 24),
);
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
switch ($form_state
->get('section')) {
case 'entity_hierarchy_embed_admin_name':
$form['#title'] .= t('Embed admin name');
$form['entity_hierarchy_embed_admin_name'] = array(
'#type' => 'textfield',
'#description' => t('This will appear as the name of this embed in the node edit screen.'),
'#default_value' => $this
->getOption('entity_hierarchy_embed_admin_name'),
);
break;
}
}
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
parent::submitOptionsForm($form, $form_state);
$section = $form_state
->get('section');
switch ($section) {
case 'entity_hierarchy_embed_admin_name':
$this
->setOption('entity_hierarchy_embed_admin_name', $form_state['values']['entity_hierarchy_embed_admin_name']);
break;
}
}
public function execute() {
parent::execute();
if (!isset($this->view->override_path)) {
$this->view->override_path = 'node';
}
$data = $this->view
->render();
if (!empty($this->view->result) || $this
->getOption('empty') || !empty($this->view->style_plugin->definition['even empty'])) {
return $data;
}
}
}