php

EntityInstanceAliasFragment.php
/**
 * Defines the entity_instance_alias_fragment entity class.
 *
 * @ContentEntityType(
 *   id = "entity_instance_alias_fragment",
 *   label = @Translation("entity_instance alias fragment"),
 *   label_collection = @Translation("Alias fragments"),
 *   label_singular = @Translation("Alias fragment"),
 *   label_plural = @Translation("Alias fragments"),
 *   label_count = @PluralTranslation(
 *     singular = "@count Alias fragment",
 *     plural = "@count Alias fragments"
 *   ),
 *   handlers = {
 *     "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage",
 *     "storage_schema" = "Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema",
 *   },
 *   base_table = "entity_instance_alias_fragment",
 *   revision_table = "entity_instance_alias_fragment_revision",
 *   entity_keys = {
 *     "id" = "id",
 *     "revision" = "revision_id",
 *     "langcode" = "langcode",
 *     "uuid" = "uuid",
 *     "published" = "status",
 *   },
 *   admin_permission = "administer alias fragments",
 *   list_cache_tags = { "route_match" },
 *   constraints = {
 *     "UniqueEntityInstanceAliasFragment" = {}
 *   }
 * )
 */

FYI: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21F…

SettingsForm.php
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this->config('user_cancel_entity_queue.settings');
    $clean_value_keys = $form_state->getCleanValueKeys();
    $clean_value_keys[] = 'submit';

    $values = array_filter($form_state->getValues(), function($value, $key) use ($clean_value_keys) {
      return !in_array($key, $clean_value_keys);
    },ARRAY_FILTER_USE_BOTH);

    foreach ($values as $key => $value) {
      $config->set($key, $value);
    }

    $config->save();
    parent::submitForm($form, $form_state);
  }
CourseDate.php
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /** @var DrupalDateTime $course_date */
    $course_date = $form_state->getValue('field_course_date');
    $this->node->set('field_course_date', $course_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, ['timezone' => 'UTC']));
    $this->node->save();
  }

Description

If you handle dates in a custom form, Drupal does not always store the date in the UTC format. It takes your local timezone. So we have to store the value of our date field as UTC.

Changed File

The file generating your form. E.g. mymodule/src/Form/CourseDate.php

04.05.2022 | Michael Ebert

CourseDate.php

ResolveConditionsWithContext.php
use ConditionAccessResolverTrait;


$conditions = [];
foreach ($conditions as $condition_id => $condition) {
  if ($condition instanceof ContextAwarePluginInterface) {
    try {
      $contexts = $this->contextRepository->getRuntimeContexts(array_values($condition->getContextMapping()));
      $this->contextHandler->applyContextMapping($condition, $contexts);
    }
    catch (MissingValueContextException $e) {
      $missing_value = TRUE;
    }
    catch (ContextException $e) {
      $missing_context = TRUE;
    }
  }
  $conditions[$condition_id] = $condition;
}

$this->resolveConditions($conditions, 'and')
UserDashboardController.php
    $menu_name = 'my_custom_menu_machine_name';
  
    $menu_tree = \Drupal::menuTree();
    // Build the typical default set of menu tree parameters.
    $parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
    // Load the tree based on this set of parameters.
    $tree = $menu_tree->load($menu_name, $parameters);
    // Transform the tree using the manipulators you want.
    $manipulators = [
      // Only show links that are accessible for the current user.
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      // Use the default sorting of menu links.
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    
    $tree = $menu_tree->transform($tree, $manipulators);

    $menu = $menu_tree->build($tree);

     // Set theme for custom styling.
    $menu['#theme'] = 'my_custom_theme';

./compat.sh gpd setup ./compat.sh gpd run

A small shell-script to check Drupal 7 projects for PHP version compatibility which outputs to csv.
Usage: ./compat.sh projectname (setup|run)
Change Version (in this example: 7.4) when needed.

compat.sh
#!/bin/sh

PROJ=$1

# Setup project dependencies.
if [ "$2" = "setup" ]; then
  composer require squizlabs/php_codesniffer
  composer require phpcompatibility/php-compatibility
fi

# Run checks.
if [ "$2" = "run" ]; then
  phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 web/sites/all/modules/ --report-csv="$PROJ"_php73_modules.csv --extensions=php,inc,module -d memory_limit=512M
  phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 web/sites/all/libraries/ --report-csv="$PROJ"_php73_lib.csv --extensions=php,inc,module -d memory_limit=512M
  phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 web/sites/all/themes/ --report-csv="$PROJ"_php73_themes.csv --extensions=php,inc,module,theme -d memory_limit=512M
fi