ViewsFieldTemplate.php in Calendar 8
File
src/Plugin/ViewsTemplateBuilder/ViewsFieldTemplate.php
View source
<?php
namespace Drupal\calendar\Plugin\ViewsTemplateBuilder;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_templates\Plugin\ViewsDuplicateBuilderBase;
use Drupal\views_templates\ViewsTemplateLoaderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ViewsFieldTemplate extends ViewsDuplicateBuilderBase {
protected $fieldManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ViewsTemplateLoaderInterface $loader, EntityFieldManagerInterface $manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $loader);
$this->fieldManager = $manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('views_templates.loader'), $container
->get('entity_field.manager'));
}
protected function getReplacements($options = NULL) {
$replacements = parent::getReplacements($options);
if (isset($options['base_path'])) {
$replacements['__BASE_PATH'] = $options['base_path'];
}
return $replacements;
}
protected function alterViewTemplateAfterCreation(array &$view_template, array $options = NULL) {
parent::alterViewTemplateAfterCreation($view_template, $options);
$field_defs = $this->fieldManager
->getBaseFieldDefinitions($this
->getDefinitionValue('entity_type'));
if (empty($field_defs['status'])) {
unset($view_template['display']['default']['display_options']['filters']['status']);
}
$this->fieldManager
->getFieldDefinitions($this
->getDefinitionValue('entity_type'), 'event');
$this->fieldManager
->getFieldStorageDefinitions('node');
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$config_form = parent::buildConfigurationForm($form, $form_state);
$replacements = $this
->getDefinitionValue('replacements');
if (isset($replacements['base_path'])) {
$config_form['base_path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Base View Path'),
'#description' => $this
->t('This view will be displayed by visiting this path on your site.'),
'#default_value' => $replacements['base_path'],
'#required' => TRUE,
];
}
return $config_form;
}
}