Commit 0515e02f authored by navneet0693's avatar navneet0693 Committed by GitHub
Browse files

Issue #3134077 by ronaldtebrake,jochemvn, bramtenhove - Drupal 9 compatibility (#2144)



We have added drupal core compatibility to our info.yml files to show all our custom work is compatible by using
core_version_requirement: ^8.8 || ^9

We have ensured to remove all deprecated code which is removed from Drupal 9. The replacement code is compatible with Drupal 8.9 as well so untill all our contributed modules are Drupal 9 ready, we are still installing Drupal 8.9.

We have added phpstan as a github action, to make sure we wont be using any deprecated code anymore either. All new code will be ran at lvl 5 strictness as well, to ensure our code is also hold to a higher standard.
Co-authored-by: jochemvn's avatarjochemvn <jochemvn@gmail.com>
Co-authored-by: ronaldtebrake's avatarronaldtebrake <ronald@goalgorilla.com>
Co-authored-by: bramtenhove's avatarBram ten Hove <bram@getopensocial.com>
parent 988aeac9
......@@ -9,6 +9,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Template\Attribute;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Drupal\comment\CommentInterface;
/**
* Implements template_preprocess_form().
......@@ -71,13 +72,13 @@ function socialbase_preprocess_form(&$variables) {
if (\Drupal::routeMatch()->getRouteName() === 'entity.comment.edit_form') {
$comment = \Drupal::routeMatch()->getParameter('comment');
if (is_object($comment)) {
if ($comment instanceof CommentInterface) {
// Display comment created date in format 'time ago'.
$created_time_ago = \Drupal::service('date.formatter')
->formatTimeDiffSince($comment->getCreatedTime(), ['granularity' => 1, 'return_as_object' => TRUE]);
$submitted = t('@time ago', ['@time' => $created_time_ago->getString()]);
$variables['submitted'] = Link::fromTextAndUrl($submitted, $comment->urlInfo('canonical'));
$variables['submitted'] = Link::fromTextAndUrl($submitted, $comment->toUrl('canonical'));
$variables['#cache']['max-age'] = $created_time_ago->getMaxAge();
// Display author information.
......@@ -100,7 +101,7 @@ function socialbase_preprocess_form(&$variables) {
'#theme' => 'username',
'#account' => $account,
];
$variables['author'] = drupal_render($username);
$variables['author'] = \Drupal::service('renderer')->render($username);
}
}
......@@ -113,7 +114,7 @@ function socialbase_preprocess_form(&$variables) {
if (\Drupal::routeMatch()->getRouteName() === 'entity.post.edit_form') {
$post_id = $element['#post_id'];
/** @var \Drupal\social_post\Entity\Post $post */
$post = entity_load('post', $post_id);
$post = \Drupal::service('entity_type.manager')->getStorage('post')->load($post_id);
// Display post created date in format 'time ago'.
$created_time_ago = \Drupal::service('date.formatter')
......
......@@ -28,7 +28,7 @@ base theme: bootstrap
# The supported Drupal version.
core: 8.x
core_version_requirement: ^8.8 || ^9
# Libraries-extend is used to attach libraries to other libraries. If the
# original library is conditionally included, the library it is extended with
......
......@@ -5,10 +5,10 @@
* The primary PHP file for the Social base theme.
*/
use Drupal\Component\Utility\Html as HtmlUtility;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Language\LanguageInterface;
use Drupal\node\NodeInterface;
use Drupal\Component\Utility\Html;
// Include all files from the includes directory.
$includes_path = dirname(__FILE__) . '/includes/*.inc';
......@@ -47,7 +47,7 @@ function socialbase_group_link($node) {
if ($group->isTranslatable() && $group->hasTranslation($curr_langcode)) {
$group = $group->getTranslation($curr_langcode);
}
$group_link = $group->link();
$group_link = $group->toLink()->toString();
}
}
return $group_link;
......@@ -79,7 +79,7 @@ function _socialbase_get_visibility_icon($title) {
break;
default:
$icon = strtolower(HtmlUtility::escape($title));
$icon = strtolower(Html::escape($title));
}
return $icon;
......
......@@ -147,7 +147,7 @@ class ThemeSuggestions extends BaseThemeSuggestions {
// For comments in activities we show the amount of attachments.
if ($file->_referringItem !== NULL) {
/* @var $item \Drupal\file\Plugin\Field\FieldType\FileItem */
/** @var \Drupal\file\Plugin\Field\FieldType\FileItem $item */
$item = $file->_referringItem;
$name = $item->getFieldDefinition()->getName();
// For field comment files we add a new suggestion.
......
......@@ -55,7 +55,7 @@ class Block extends PreprocessBase {
$prefix = '';
// If socialbase is one of the basetheme, we need a prefix for block ids.
if (array_key_exists('socialbase', $theme->getBaseThemes())) {
if (array_key_exists('socialbase', $theme->getBaseThemeExtensions())) {
$prefix = $theme->getName();
}
......@@ -73,7 +73,7 @@ class Block extends PreprocessBase {
if (in_array($region, $regions_card)) {
$variables['card'] = TRUE;
if (array_key_exists('socialbase', $theme->getBaseThemes())) {
if (array_key_exists('socialbase', $theme->getBaseThemeExtensions())) {
$prefix = $theme->getName() . '_';
}
......@@ -150,7 +150,7 @@ class Block extends PreprocessBase {
$block = BlockEntity::load('search_content_block_header');
if (!empty($block)) {
$block_output = \Drupal::entityManager()
$block_output = \Drupal::service('entity_type.manager')
->getViewBuilder('block')
->view($block);
......
......@@ -28,8 +28,8 @@ class FileLink extends BaseFileLink {
// Check if socialbase is one of the base themes.
// Then get the path to socialbase theme and provide a variable
// that can be used in the template for a path to the icons.
if (array_key_exists('socialbase', $theme->getBaseThemes())) {
$basethemes = $theme->getBaseThemes();
if (array_key_exists('socialbase', $theme->getBaseThemeExtensions())) {
$basethemes = $theme->getBaseThemeExtensions();
$variables['path_to_socialbase'] = $basethemes['socialbase']->getPath();
}
......
......@@ -38,7 +38,7 @@ class FormElementLabel extends BaseFormElementLabel {
// Date fields that need labels to distinguish date from time fields
// These include daterange fields already as well.
// @TODO update date fields of event to daterange fields and remove
// @todo update date fields of event to daterange fields and remove
// the last 4 variables of this array.
$date_fields = [
'edit-field-date-0-value-time',
......
......@@ -7,6 +7,7 @@ use Drupal\bootstrap\Utility\Element;
use Drupal\bootstrap\Utility\Variables;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\group\Entity\GroupContent;
use Drupal\node\NodeInterface;
/**
* Pre-processes variables for the "node" theme hook.
......@@ -52,7 +53,7 @@ class Node extends PreprocessBase {
'#theme' => 'username',
'#account' => $account,
];
$variables['author'] = drupal_render($username);
$variables['author'] = \Drupal::service('renderer')->render($username);
}
if (isset($variables['elements']['#node']) && !isset($variables['created_date_formatted'])) {
......@@ -126,7 +127,7 @@ class Node extends PreprocessBase {
}
}
if ($node->status->value == NODE_NOT_PUBLISHED) {
if ($node->status->value == NodeInterface::NOT_PUBLISHED) {
$variables['status_label'] = t('unpublished');
}
......
......@@ -114,7 +114,7 @@ class Page extends PreprocessBase {
// restrains for TB-4116 I've added an additional rule to this quick-fix
// solution.
// @see https://www.drupal.org/project/social/issues/3119191
// @todo: remove the if statement below and fix logic mentioned above.
// @todo remove the if statement below and fix logic mentioned above.
$route = \Drupal::routeMatch()->getRouteName();
$routes_remove_complementary_class = [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment