Skip to content

Commit

Permalink
Merge pull request #97 from gitmonkee/feature/fix-deprecations-in-dru…
Browse files Browse the repository at this point in the history
…pal9.5.10

Feature/fix deprecations in drupal9.5.10
  • Loading branch information
jez500 authored Aug 7, 2023
2 parents 80f6f6f + f58a23f commit 23ef25e
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 55 deletions.
11 changes: 8 additions & 3 deletions dvf_ckan/src/Plugin/Visualisation/Source/CkanResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\ckan_connect\Parser\CkanResourceUrlParserInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\dvf\DvfHelpers;
use Drupal\dvf\Plugin\VisualisationInterface;
Expand Down Expand Up @@ -96,6 +97,8 @@ class CkanResource extends VisualisationSourceBase implements ContainerFactoryPl
* The CKAN resource URL parser.
* @param \Drupal\dvf\DvfHelpers $dvf_helpers
* The DVF helpers.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file URL generator.
*/
public function __construct(
array $configuration,
Expand All @@ -108,9 +111,10 @@ public function __construct(
CacheBackendInterface $cache,
CkanClientInterface $ckan_client,
CkanResourceUrlParserInterface $ckan_resource_url_parser,
DvfHelpers $dvf_helpers
DvfHelpers $dvf_helpers,
FileUrlGeneratorInterface $file_url_generator
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $visualisation, $module_handler, $logger, $http_client);
parent::__construct($configuration, $plugin_id, $plugin_definition, $visualisation, $module_handler, $logger, $http_client, $file_url_generator);
$this->cache = $cache;
$this->ckanClient = $ckan_client;
$this->ckanResourceUrlParser = $ckan_resource_url_parser;
Expand Down Expand Up @@ -152,7 +156,8 @@ public static function create(
$container->get('cache.dvf_ckan'),
$container->get('ckan_connect.client'),
$container->get('ckan_connect.resource_url_parser'),
$container->get('dvf.helpers')
$container->get('dvf.helpers'),
$container->get('file_url_generator')
);
}

Expand Down
11 changes: 8 additions & 3 deletions dvf_csv/src/Plugin/Visualisation/Source/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\dvf\Plugin\VisualisationInterface;
Expand Down Expand Up @@ -67,6 +68,8 @@ class CsvFile extends VisualisationSourceBase implements ContainerFactoryPluginI
* The HTTP client.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file URL generator.
*/
public function __construct(
array $configuration,
Expand All @@ -76,9 +79,10 @@ public function __construct(
ModuleHandlerInterface $module_handler,
LoggerInterface $logger,
Client $http_client,
CacheBackendInterface $cache
CacheBackendInterface $cache,
FileUrlGeneratorInterface $file_url_generator
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $visualisation, $module_handler, $logger, $http_client);
parent::__construct($configuration, $plugin_id, $plugin_definition, $visualisation, $module_handler, $logger, $http_client, $file_url_generator);
$this->cache = $cache;
}

Expand Down Expand Up @@ -108,7 +112,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('module_handler'),
$container->get('logger.channel.dvf'),
$container->get('http_client'),
$container->get('cache.dvf_csv')
$container->get('cache.dvf_csv'),
$container->get('file_url_generator')
);
}

Expand Down
13 changes: 9 additions & 4 deletions dvf_json/src/Plugin/Visualisation/Source/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\dvf\DvfHelpers;
Expand Down Expand Up @@ -78,6 +79,8 @@ class JsonFile extends VisualisationSourceBase implements ContainerFactoryPlugin
* The cache backend.
* @param \Drupal\dvf\DvfHelpers $dvf_helpers
* The DVF helpers.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file URL generator.
*/
public function __construct(
array $configuration,
Expand All @@ -88,9 +91,10 @@ public function __construct(
LoggerInterface $logger,
Client $http_client,
CacheBackendInterface $cache,
DvfHelpers $dvf_helpers
DvfHelpers $dvf_helpers,
FileUrlGeneratorInterface $file_url_generator
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $visualisation, $module_handler, $logger, $http_client);
parent::__construct($configuration, $plugin_id, $plugin_definition, $visualisation, $module_handler, $logger, $http_client, $file_url_generator);
$this->cache = $cache;
$this->dvfHelpers = $dvf_helpers;
}
Expand Down Expand Up @@ -122,7 +126,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('logger.channel.dvf'),
$container->get('http_client'),
$container->get('cache.dvf_json'),
$container->get('dvf.helpers')
$container->get('dvf.helpers'),
$container->get('file_url_generator')
);
}

Expand Down Expand Up @@ -191,7 +196,7 @@ public function getRecords() {
}

foreach ($this->getFields() as $field_key => $field_label) {
foreach ($json->data() as $record_id => $record) {
foreach ($json->getData() as $record_id => $record) {
if (!isset($records[$record_id])) {
$records[$record_id] = new \stdClass();
}
Expand Down
44 changes: 42 additions & 2 deletions src/Controller/DvfHelpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,53 @@
namespace Drupal\dvf\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Render\RendererInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provide information for DvfHelp page.
*/
class DvfHelpController extends ControllerBase {

/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected $moduleExtensionList;

/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;

/**
* Constructs a new DvfHelpController object.
*
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
* The module extension list.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(ModuleExtensionList $extension_list_module, RendererInterface $renderer) {
$this->moduleExtensionList = $extension_list_module;
$this->renderer = $renderer;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('extension.list.module'),
$container->get('renderer')
);
}

/**
* Returns the help page information ready to load in partial twig template.
*
Expand All @@ -21,7 +61,7 @@ class DvfHelpController extends ControllerBase {
*/
public function helpPage($topic) {

$dvf_path = drupal_get_path('module', 'dvf');
$dvf_path = $this->moduleExtensionList->getPath('dvf');
$file_path = $dvf_path . '/templates/help/';
$css_path = base_path() . $dvf_path . '/css/help.css';

Expand All @@ -38,7 +78,7 @@ public function helpPage($topic) {
'#css' => $css_path,
];

$output = \Drupal::service('renderer')->renderRoot($build);
$output = $this->renderer->renderRoot($build);
$response = new Response();

return $response->setContent($output);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldType/VisualisationFileItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setValue($values, $notify = TRUE) {
}

if (is_string($values['options'])) {
$values['options'] = unserialize($values['options']);
$values['options'] = unserialize($values['options'], ['allowed_classes' => FALSE]);
}

parent::setValue($values, $notify);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldType/VisualisationUrlItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function setValue($values, $notify = TRUE) {
}

if (is_string($values['options'])) {
$values['options'] = unserialize($values['options']);
$values['options'] = unserialize($values['options'], ['allowed_classes' => FALSE]);
}

parent::setValue($values, $notify);
Expand Down
46 changes: 37 additions & 9 deletions src/Plugin/Field/FieldWidget/VisualisationFileWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace Drupal\dvf\Plugin\Field\FieldWidget;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\dvf\FieldWidgetTrait;
use Drupal\dvf\Plugin\VisualisationManager;
use Drupal\file\Element\ManagedFile;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Plugin implementation of the 'dvf_file_default' field widget.
Expand All @@ -23,6 +27,36 @@ class VisualisationFileWidget extends WidgetBase {

use FieldWidgetTrait;

/**
* The visualisation manager.
*
* @var \Drupal\dvf\Plugin\VisualisationManager
*/
protected $visualisationManager;

/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;

/**
* {@inheritdoc}
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, VisualisationManager $visualisationManager, RendererInterface $renderer) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->visualisationManager = $visualisationManager;
$this->renderer = $renderer;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], $container->get('plugin.manager.visualisation'), $container->get('renderer'));
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -50,7 +84,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#cardinality' => $cardinality,
];

$element['file']['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
$element['file']['#description'] = $this->renderer->renderPlain($file_upload_help);

// Default value for managed file expects an array of fids.
if (!empty($values[$delta]['file'])) {
Expand All @@ -72,7 +106,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#options' => $this->getVisualisationStyleOptions(),
'#empty_option' => $this->t('- Select -'),
'#empty_value' => '',
'#default_value' => isset($items[$delta]->options['visualisation_style']) ? $items[$delta]->options['visualisation_style'] : '',
'#default_value' => $items[$delta]->options['visualisation_style'] ?? '',
'#required' => $element['#required'],
'#ajax' => [
'callback' => [$this, 'updateVisualisationOptions'],
Expand Down Expand Up @@ -164,9 +198,6 @@ public static function value(array $element, $input, FormStateInterface $form_st
protected function getVisualisationPlugin(FieldItemListInterface $items, $delta, array $form, FormStateInterface $form_state) {
$values = $this->getFieldValue($items, $delta, $form, $form_state);

/** @var \Drupal\dvf\Plugin\VisualisationManagerInterface $plugin_manager */
$plugin_manager = \Drupal::service('plugin.manager.visualisation');

$plugin_id = $this->fieldDefinition->getType();
$plugin_configuration = [
'options' => [
Expand Down Expand Up @@ -196,10 +227,7 @@ protected function getVisualisationPlugin(FieldItemListInterface $items, $delta,
$plugin_configuration['style']['options'] = $values[$delta]['options']['visualisation_style_options'];
}

/** @var \Drupal\dvf\Plugin\VisualisationInterface $plugin */
$plugin = $plugin_manager->createInstance($plugin_id, $plugin_configuration);

return $plugin;
return $this->visualisationManager->createInstance($plugin_id, $plugin_configuration);
}

}
37 changes: 28 additions & 9 deletions src/Plugin/Field/FieldWidget/VisualisationUrlWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Drupal\dvf\Plugin\Field\FieldWidget;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\dvf\FieldWidgetTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\dvf\Plugin\VisualisationManager;

/**
* Plugin implementation of the 'dvf_url_default' field widget.
Expand All @@ -22,6 +25,28 @@ class VisualisationUrlWidget extends WidgetBase {

use FieldWidgetTrait;

/**
* The visualisation manager.
*
* @var \Drupal\dvf\Plugin\VisualisationManager
*/
protected $visualisationManager;

/**
* {@inheritdoc}
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, VisualisationManager $visualisationManager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->visualisationManager = $visualisationManager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], $container->get('plugin.manager.visualisation'));
}

/**
* {@inheritdoc}
*/
Expand All @@ -33,7 +58,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#type' => 'url',
'#title' => $this->t('URL'),
'#description' => $this->t('External url to dataset.'),
'#default_value' => isset($items[$delta]->uri) ? $items[$delta]->uri : NULL,
'#default_value' => $items[$delta]->uri ?? NULL,
'#maxlength' => 2048,
'#required' => $element['#required'],
];
Expand All @@ -52,7 +77,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#options' => $this->getVisualisationStyleOptions(),
'#empty_option' => $this->t('- Select -'),
'#empty_value' => '',
'#default_value' => isset($items[$delta]->options['visualisation_style']) ? $items[$delta]->options['visualisation_style'] : '',
'#default_value' => $items[$delta]->options['visualisation_style'] ?? '',
'#required' => $element['#required'],
'#ajax' => [
'callback' => [$this, 'updateVisualisationOptions'],
Expand Down Expand Up @@ -95,9 +120,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
protected function getVisualisationPlugin(FieldItemListInterface $items, $delta, array $form, FormStateInterface $form_state) {
$values = $this->getFieldValue($items, $delta, $form, $form_state);

/** @var \Drupal\dvf\Plugin\VisualisationManagerInterface $plugin_manager */
$plugin_manager = \Drupal::service('plugin.manager.visualisation');

$plugin_id = $this->fieldDefinition->getType();
$plugin_configuration = [
'options' => [
Expand All @@ -122,10 +144,7 @@ protected function getVisualisationPlugin(FieldItemListInterface $items, $delta,
$plugin_configuration['style']['options'] = $values[$delta]['options']['visualisation_style_options'];
}

/** @var \Drupal\dvf\Plugin\VisualisationInterface $plugin */
$plugin = $plugin_manager->createInstance($plugin_id, $plugin_configuration);

return $plugin;
return $this->visualisationManager->createInstance($plugin_id, $plugin_configuration);
}

}
Loading

0 comments on commit 23ef25e

Please sign in to comment.