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

Add function node_types_rebuild() #133

Open
wants to merge 2 commits into
base: main
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
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ parameters:
path: src/Routing/HookMenuRoutes.php

-
message: "#^Cannot access offset '\\#title' on mixed\\.$#"
message: "#^Cannot access offset '\\#id' on mixed\\.$#"
count: 1
path: src/Theme/HookPreprocess.php

-
message: "#^Offset '\\#id' might not exist on array\\<int\\|string, mixed\\>\\|string\\.$#"
message: "#^Cannot access offset '\\#title' on mixed\\.$#"
count: 1
path: src/Theme/HookPreprocess.php

Expand Down
1 change: 1 addition & 0 deletions src/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FormBuilder extends CoreFormBuilder
{
/**
* @param FormStateInterface|mixed[] $form_state
* @param-out FormStateInterface $form_state
* @return mixed[]
*/
public function buildForm(mixed $form_arg, FormStateInterface|array &$form_state): array
Expand Down
2 changes: 1 addition & 1 deletion src/Theme/HookPreprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Retrofit\Drupal\Entity\WrappedConfigEntity;

/**
* @phpstan-type Variables array<string, string|array<int|string, mixed>>
* @phpstan-type Variables array<string, mixed>
* @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
*/
final class HookPreprocess
Expand Down
2 changes: 2 additions & 0 deletions src/Theme/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class Registry extends CoreRegistry
{
/**
* @param RegistryData $cache
* @param-out array $cache
*/
protected function processExtension(array &$cache, $name, $type, $theme, $path): void
{
Expand Down Expand Up @@ -72,6 +73,7 @@ protected function processExtension(array &$cache, $name, $type, $theme, $path):

/**
* @param array<string, array{'preprocess functions': callable[]}> $cache
* @param-out array $cache
*/
protected function postProcessExtension(array &$cache, ActiveTheme $theme): void
{
Expand Down
8 changes: 7 additions & 1 deletion src/functions/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\Core\Database\Query\Merge;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\RevisionableInterface;
Expand Down Expand Up @@ -131,6 +130,7 @@ function entity_language(string $entity_type, EntityInterface $entity): ?string

/**
* @param array<string, mixed> $elements
* @param-out array $elements
* @return array<string, mixed>
*/
function element_children(array &$elements, bool $sort = false): array
Expand All @@ -147,6 +147,7 @@ function drupal_get_path(string $type, string $name): string

/**
* @param array<string, mixed> $element
* @param-out array $element
* @param string[]|null $children_keys
*/
function drupal_render_children(array &$element, array $children_keys = null): string
Expand All @@ -165,6 +166,7 @@ function drupal_render_children(array &$element, array $children_keys = null): s

/**
* @param array<string, mixed> $elements
* @param-out array $elements
* @phpstan-ignore-next-line
*/
function drupal_render(array &$elements): MarkupInterface|string
Expand Down Expand Up @@ -348,6 +350,7 @@ function drupal_clean_css_identifier(string $identifier, array $filter = [

/**
* @param array<int|string, mixed> $array
* @param-out array $array
* @param array<int, int|string> $parents
*/
function &drupal_array_get_nested_value(array &$array, array $parents, ?bool &$key_exists = null): mixed
Expand All @@ -357,6 +360,7 @@ function &drupal_array_get_nested_value(array &$array, array $parents, ?bool &$k

/**
* @param array<int|string, mixed> $array
* @param-out array $array
* @param array<int, int|string> $parents
*/
function drupal_array_set_nested_value(array &$array, array $parents, mixed $value, bool $force = false): void
Expand Down Expand Up @@ -402,6 +406,7 @@ function drupal_get_query_array(string $query): array
function drupal_goto(string $path = '', array $options = [], int $http_response_code = 302): void
{
\Drupal::moduleHandler()->alter('drupal_goto', $path, $options, $http_response_code);
assert(is_string($path) && is_array($options) && is_int($http_response_code));
$url = \Drupal::pathValidator()->getUrlIfValidWithoutAccessCheck($path);
if ($url !== false) {
$url->mergeOptions($options);
Expand All @@ -426,6 +431,7 @@ function drupal_json_encode(mixed $var): string

/**
* @param array<string, mixed>|object $record
* @param-out array|object $record
* @param string[] $primary_keys
*/
function drupal_write_record(string $table, array|object &$record, array|string $primary_keys = []): int|false
Expand Down
6 changes: 5 additions & 1 deletion src/functions/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

use Drupal\Core\Form\FormStateInterface;
use Retrofit\Drupal\Form\DrupalGetForm;
use Retrofit\Drupal\Form\FormBuilder;

/**
* @param mixed[] $form_state
* @param-out FormStateInterface $form_state
* @return mixed[]
*/
function drupal_build_form(string $form_id, array &$form_state): array
{
$form_object = \Drupal::classResolver(DrupalGetForm::class);
$form_object->setFormId($form_id);
return \Drupal::formBuilder()->buildForm($form_object, $form_state);
$form_builder = \Drupal::formBuilder();
assert($form_builder instanceof FormBuilder);
return $form_builder->buildForm($form_object, $form_state);
}

function drupal_form_submit(string $form_id, FormStateInterface $form_state): void
Expand Down
11 changes: 11 additions & 0 deletions src/functions/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\StorageCacheInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeTypeInterface;
Expand Down Expand Up @@ -72,3 +74,12 @@ function node_type_delete(string $type): void
$nodeType = NodeType::load($type);
$nodeType?->delete();
}

function node_types_rebuild(): void
{
$tags = \Drupal::config('node_type')->getCacheTags();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is valid. There isn't a node_type config object.

$tags[] = 'config:node_type_list';
Cache::invalidateTags($tags);
Comment on lines +81 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is correct. We probably want the value of getListCacheTags from the node_type entity type definition.

$storage = \Drupal::service('config.storage');
$storage->resetListCache();
}
2 changes: 2 additions & 0 deletions tests/src/Integration/Database/DrupalWriteRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public function testWritingRecord(): void
'timestamp' => time(),
];
$result = drupal_write_record('watchdog', $record);
assert(is_array($record));
self::assertEquals(1, $result);
self::assertArrayHasKey('wid', $record);
self::assertEquals(1, $record['wid']);
$record['message'] = 'test2';
$result = drupal_write_record('watchdog', $record, ['wid']);
assert(is_array($record));
self::assertEquals(2, $result);
self::assertArrayHasKey('wid', $record);
self::assertEquals(1, $record['wid']);
Expand Down
Loading