Skip to content
Snippets Groups Projects

issue #3467834: TypeError:...

Closed shaikh sadab requested to merge issue/views_json_source-3467834:8.x-1.x into 2.0.x
3 files
+ 21
18
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -3,18 +3,18 @@
@@ -3,18 +3,18 @@
namespace Drupal\views_json_source\Plugin\views\query;
namespace Drupal\views_json_source\Plugin\views\query;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Utility\Token;
use Drupal\Core\Utility\Token;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewExecutable;
use Drupal\views_json_source\Event\PreCacheEvent;
use Drupal\views_json_source\Event\PreCacheEvent;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\ClientInterface;
 
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
 
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
/**
* Base query handler for views_json_source.
* Base query handler for views_json_source.
@@ -58,7 +58,7 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -58,7 +58,7 @@ class ViewsJsonQuery extends QueryPluginBase {
/**
/**
* The event dispatcher.
* The event dispatcher.
*
*
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
*/
protected $eventDispatcher;
protected $eventDispatcher;
@@ -77,11 +77,11 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -77,11 +77,11 @@ class ViewsJsonQuery extends QueryPluginBase {
protected $token;
protected $token;
/**
/**
* The messenger.
* The logger instance.
*
*
* @var \Drupal\Core\Messenger\MessengerInterface
* @var \Psr\Log\LoggerInterface
*/
*/
protected $messenger;
protected $logger;
/**
/**
* To store the url filter info.
* To store the url filter info.
@@ -124,7 +124,7 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -124,7 +124,7 @@ class ViewsJsonQuery extends QueryPluginBase {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, CacheBackendInterface $cache, TimeInterface $time, ContainerAwareEventDispatcher $event_dispatcher, ClientInterface $http_client, Token $token, MessengerInterface $messenger) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, CacheBackendInterface $cache, TimeInterface $time, EventDispatcherInterface $event_dispatcher, ClientInterface $http_client, Token $token, LoggerInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->config = $config;
$this->config = $config;
@@ -133,7 +133,7 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -133,7 +133,7 @@ class ViewsJsonQuery extends QueryPluginBase {
$this->eventDispatcher = $event_dispatcher;
$this->eventDispatcher = $event_dispatcher;
$this->httpClient = $http_client;
$this->httpClient = $http_client;
$this->token = $token;
$this->token = $token;
$this->messenger = $messenger;
$this->logger = $logger;
}
}
/**
/**
@@ -150,7 +150,7 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -150,7 +150,7 @@ class ViewsJsonQuery extends QueryPluginBase {
$container->get('event_dispatcher'),
$container->get('event_dispatcher'),
$container->get('http_client'),
$container->get('http_client'),
$container->get('token'),
$container->get('token'),
$container->get('messenger')
$container->get('logger.channel.views_json_source')
);
);
}
}
@@ -264,14 +264,14 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -264,14 +264,14 @@ class ViewsJsonQuery extends QueryPluginBase {
$data->contents = $this->fetchFile($url);
$data->contents = $this->fetchFile($url);
}
}
catch (\Exception $e) {
catch (\Exception $e) {
$this->messenger->addMessage($e->getMessage(), 'error');
$this->logger->error($e->getMessage());
return;
return;
}
}
// When content is empty, parsing it is pointless.
// When content is empty, parsing it is pointless.
if (!$data->contents) {
if (!$data->contents) {
if ($this->options['show_errors']) {
if ($this->options['show_errors']) {
$this->messenger->addMessage($this->t('Views JSON Backend: File is empty.'), 'warning');
$this->logger->warning($this->t('Views JSON Backend: File is empty.'));
}
}
return;
return;
}
}
@@ -297,12 +297,12 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -297,12 +297,12 @@ class ViewsJsonQuery extends QueryPluginBase {
$this->t('Malformed UTF-8 characters, possibly incorrectly encoded'),
$this->t('Malformed UTF-8 characters, possibly incorrectly encoded'),
];
];
$msg = $tmp[json_last_error()] . ' - ' . $this->options['json_file'];
$msg = $tmp[json_last_error()] . ' - ' . $this->options['json_file'];
$this->messenger->addMessage($msg, 'error');
$this->logger->error($msg);
}
}
else {
else {
$this->messenger->addMessage($this->t(
$this->logger->error($this->t(
'Views JSON Backend: Parse error') .
'Views JSON Backend: Parse error') .
' - ' . $this->options['json_file'], 'error'
' - ' . $this->options['json_file']
);
);
}
}
}
}
@@ -496,11 +496,10 @@ class ViewsJsonQuery extends QueryPluginBase {
@@ -496,11 +496,10 @@ class ViewsJsonQuery extends QueryPluginBase {
catch (\Exception $e) {
catch (\Exception $e) {
$view->result = [];
$view->result = [];
if (!empty($view->live_preview)) {
if (!empty($view->live_preview)) {
$this->messenger->addMessage(time());
$this->logger->error($e->getMessage());
$this->messenger->addMessage($e->getMessage(), 'error');
}
}
else {
else {
$this->messenger->addMessage($e->getMessage());
$this->logger->notice($e->getMessage());
}
}
}
}
}
}
Loading