Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-139: Use JsonEncoded everywhere possible. #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Drupal\oe_webtools_europa_search\Plugin\Block;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\oe_webtools\Component\Render\JsonEncoded;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ public function build() {
'#attached' => ['library' => ['oe_webtools/drupal.webtools-smartloader']],
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => Json::encode($search_widget_json),
'#value' => new JsonEncoded($search_widget_json),
'#attributes' => ['type' => 'application/json'],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
declare(strict_types=1);

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\oe_webtools\Component\Render\JsonEncoded;

/**
* Implements hook_page_bottom().
Expand Down Expand Up @@ -51,7 +52,7 @@ function oe_webtools_laco_widget_page_bottom(array &$page_bottom) {
$page_bottom['oe_webtools_cookie_consent'][] = [
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => json_encode($json),
'#value' => new JsonEncoded($json),
'#attributes' => ['type' => 'application/json'],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\oe_webtools_maps\Component\Render\JsonEncoded;
use Drupal\oe_webtools\Component\Render\JsonEncoded;

/**
* Displays a Geofield as a map using the Webtools Maps service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace Drupal\oe_webtools_social_share\Plugin\Block;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\Markup;
use Drupal\oe_webtools\Component\Render\JsonEncoded;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -88,7 +87,7 @@ public function build() {
return [
'#theme' => 'oe_webtools_social_share',
'#title' => $this->t('Share this page'),
'#icons_json' => Markup::create(Json::encode($social_share_json)),
'#icons_json' => new JsonEncoded($social_share_json),
'#attached' => ['library' => ['oe_webtools/drupal.webtools-smartloader']],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Drupal\oe_webtools_maps\Component\Render;
namespace Drupal\oe_webtools\Component\Render;

use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Serialization\Json;
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Field/FieldFormatter/WebtoolsSnippetFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Drupal\Component\Serialization\Json;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Render\Markup;
use Drupal\oe_webtools\Component\Render\JsonEncoded;

/**
* Plugin implementation of the 'webtools_snippet' formatter.
Expand Down Expand Up @@ -35,7 +35,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
// We need to properly escape the json content before outputting in the
// page. We cannot use twig escaping mechanism as it will use html
// entities. Json::encode takes care of it.
'#value' => Markup::create(Json::encode(Json::decode($item->get('value')->getValue()))),
'#value' => new JsonEncoded(Json::decode($item->get('value')->getValue())),
'#attributes' => ['type' => 'application/json'],
];
}
Expand Down