From bacb4456338db7de92135239b50931979a04be21 Mon Sep 17 00:00:00 2001
From: Konstantinos Platis <konstantinos.platis@cern.ch>
Date: Mon, 8 Feb 2021 15:28:34 +0000
Subject: [PATCH] Remove deprecated functions of D9 (module passes d9-readiness
 scan)

---
 CHANGELOG.md                                      |  3 +++
 cern_components.info.yml                          |  2 +-
 cern_components.module                            |  4 ++--
 composer.json                                     |  2 +-
 src/TwigExtension/CernComponentsTwigExtension.php | 14 +++++++-------
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 09f94a5d..b98b6a1e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [2.7.13] - 8/02/2021
+- Remove deprecated functions of D9 (module passes d9-readiness scan)
+
 ## [2.7.12] - 8/02/2021
 - Add core: 8.x to fix enabling issue
 
diff --git a/cern_components.info.yml b/cern_components.info.yml
index 6c7f2600..199899d9 100755
--- a/cern_components.info.yml
+++ b/cern_components.info.yml
@@ -3,7 +3,7 @@ type: module
 description: "Provides all the necessary modules regarding CERN Web Components."
 core: 8.x
 core_version_requirement: ^8 || ^9
-version: 2.7.12
+version: 2.7.13
 package: CERN Components
 dependencies:
   - components:components (>=8.x-1.1-alpha1)
diff --git a/cern_components.module b/cern_components.module
index fa3f6c16..d043d6be 100755
--- a/cern_components.module
+++ b/cern_components.module
@@ -2,7 +2,7 @@
 
 use Drupal\ui_patterns\UiPatterns;
 use Drupal\Component\Utility\Html;
-
+use Drupal\node\Entity\Node;
 
 
 /**
@@ -18,7 +18,7 @@ function cern_components_preprocess(&$variables, $hook) {
       $variables['cern_node_type'] = \Drupal::routeMatch()->getParameter('node')->getType();
     // if $node is string (for revisions)
     } else if (is_string($object)) {
-      $variables['cern_node_type'] = node_load($object)->getType();
+      $variables['cern_node_type'] = Node::load($object)->getType();
     }
   }
 
diff --git a/composer.json b/composer.json
index a6a529c8..e9a52fa4 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
 {
     "name": "drupal/cern-components",
     "description": "Defines a set of re-usable patterns for the CERN Drupal infrastructure",
-    "version": "2.7.12",
+    "version": "2.7.13",
     "type": "drupal-custom-module",
     "license": "GPL-2.0-or-later",
     "authors": [
diff --git a/src/TwigExtension/CernComponentsTwigExtension.php b/src/TwigExtension/CernComponentsTwigExtension.php
index 9e37b61f..a3fb4861 100755
--- a/src/TwigExtension/CernComponentsTwigExtension.php
+++ b/src/TwigExtension/CernComponentsTwigExtension.php
@@ -10,15 +10,15 @@ use Drupal\Core\Menu\MenuLinkTree;
 use Drupal\Core\Menu\MenuTreeParameters;
 use Drupal\Core\Url;
 use Drupal\Component\Utility\Xss;
+use Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList;
 use Drupal\menu_link_content\Entity\MenuLinkContent;
 use Drupal\paragraphs\Entity\Paragraph;
 use Drupal\views\Entity\View;
 use Drupal\views\Views;
 use Drupal\viewsreference\Plugin\Field\FieldType\ViewsReferenceItem;
 use Symfony\Component\HttpFoundation\RequestStack;
-use Drupal\file\Entity\File;
-use Drupal\image\Entity\ImageStyle;
 use Drupal\node\Entity\Node;
+use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
 
 /**
  * Class CernComponentsTwigExtension.
@@ -176,11 +176,11 @@ class CernComponentsTwigExtension extends \Twig_Extension {
   public function formatFieldDate($field, $type, $format = '') {
     $field = reset($field);
     if (isset($field['#items'])) {
-      /** @var $items \Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList */
+      /** @var $items DateTimeFieldItemList */
       $items = $field['#items'];
       $value = $items->get(0)->getValue();
       if (isset($value['value']) && !empty($value['value'])) {
-        $initial_format = mb_strlen($value['value']) > 10 ? DATETIME_DATETIME_STORAGE_FORMAT : 'Y-m-d';
+        $initial_format = mb_strlen($value['value']) > 10 ? DateTimeItemInterface::DATETIME_STORAGE_FORMAT : 'Y-m-d';
         $value = \DateTime::createFromFormat($initial_format, $value['value'], new \DateTimeZone('UTC'))->format('U');
         return ['#markup' => \Drupal::service('date.formatter')->format($value, $type, $format)];
       }
@@ -672,7 +672,7 @@ class CernComponentsTwigExtension extends \Twig_Extension {
     // if $node is string (for revisions)
     } else if (is_string($node)) {
       // Get node nid
-      $node = node_load($node);
+      $node = Node::load($node);
     }
     if (isset($node)) {
       if ($language == 'en' && $node->hasTranslation('fr') && $node->hasTranslation('en') && $node->getTranslation('fr')->isPublished()) {
@@ -704,7 +704,7 @@ class CernComponentsTwigExtension extends \Twig_Extension {
 
     // Current language Code
     $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
-    
+
     // Get paragraph object
     $paragraph_object = Paragraph::load($paragraph_id);
 
@@ -718,7 +718,7 @@ class CernComponentsTwigExtension extends \Twig_Extension {
 
     // More info from CDS
     $info = $paragraph_object->getFields()['field_p_gallery_cds_image']->getValue();
-    
+
     return($info);
   }
 
-- 
GitLab