Skip to content
Merged
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
10 changes: 8 additions & 2 deletions analyze.module
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ function analyze_local_tasks_alter(array &$local_tasks): void {
* Implements hook_form_alter().
*
* @phpstan-param array<string, mixed> $form
* @phpstan-param \Drupal\Core\Form\FormStateInterface $form_state
* @phpstan-param string $form_id
*
* @param-out array<string, mixed> $form
*/
function analyze_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
if ($form_id !== 'analyze_analyze_settings') {
Expand Down Expand Up @@ -144,12 +148,14 @@ function analyze_form_alter(array &$form, FormStateInterface $form_state, string
/**
* Helper to add Analyze settings to a form.
*
* @param mixed[] $form
* The form.
* @param array<string, mixed> $form
* The form array.
* @param string $entity_type
* The entity type the settings are for.
* @param string|null $bundle
* The bundle the settings are for.
*
* @param-out array<string, mixed> $form
*/
function analyze_add_settings_form(array &$form, string $entity_type, ?string $bundle = NULL): void {
// If the user doesn't have the permission.
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
working_dir: /src
command: bash -c "./scripts/run-drupal-lint.sh"
environment:
TARGET_DRUPAL_CORE_VERSION: 10
TARGET_DRUPAL_CORE_VERSION: 11
volumes:
- .:/src

Expand All @@ -16,7 +16,7 @@ services:
working_dir: /src
command: bash -c "./scripts/run-drupal-lint-auto-fix.sh"
environment:
TARGET_DRUPAL_CORE_VERSION: 10
TARGET_DRUPAL_CORE_VERSION: 11
volumes:
- .:/src

Expand All @@ -27,6 +27,6 @@ services:
command: bash -c "/src/scripts/run-drupal-check.sh"
tty: true
environment:
DRUPAL_RECOMMENDED_PROJECT: 10.3.x-dev
DRUPAL_RECOMMENDED_PROJECT: 11.x-dev
volumes:
- .:/src
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ private function getImageCount(EntityInterface $entity): int {
$matches = [];
preg_match_all('/<img/', $render, $matches);

if (isset($matches[0])) {
$return = count($matches[0]);
}
$return = count($matches[0]);

return $return;
}
Expand All @@ -160,9 +158,7 @@ private function getHtml(EntityInterface $entity): string {
$rendered = $this->renderer->render($view);

// Handle both string and Markup object cases.
return is_object($rendered) && method_exists($rendered, '__toString')
? $rendered->__toString()
: (string) $rendered;
return (string) $rendered;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/AnalyzePluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function __construct(
* @phpstan-param array<string, mixed> $configuration
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
// @phpstan-ignore-next-line - This is intended to be called by subclasses
return new static(
$configuration,
$plugin_id,
Expand All @@ -71,7 +72,7 @@ public static function create(ContainerInterface $container, array $configuratio
*/
protected function getConfigFactory(): ConfigFactoryInterface {
if (!$this->configFactory) {
$this->configFactory = \Drupal::service('config.factory');
throw new \RuntimeException('Config factory not injected. Please ensure the plugin is created using dependency injection.');
}
return $this->configFactory;
}
Expand Down Expand Up @@ -302,7 +303,7 @@ protected function saveEntityTypeSettings(string $entity_type_id, array $setting
* The settings to save.
*/
public function saveSettings(string $entity_type_id, ?string $bundle, array $settings): void {
$config = \Drupal::configFactory()->getEditable('analyze.settings');
$config = $this->getConfigFactory()->getEditable('analyze.settings');
$current = $config->get('status') ?? [];

// Save enabled state.
Expand All @@ -313,7 +314,7 @@ public function saveSettings(string $entity_type_id, ?string $bundle, array $set

// Save detailed settings if present.
if (isset($settings['settings'])) {
$detailed_config = \Drupal::configFactory()->getEditable('analyze.plugin_settings');
$detailed_config = $this->getConfigFactory()->getEditable('analyze.plugin_settings');
$key = sprintf('%s.%s.%s', $entity_type_id, $bundle, $this->getPluginId());
$detailed_config->set($key, $settings['settings'])->save();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/AnalyzeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function __construct(
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
public static function create(ContainerInterface $container): static {
// @phpstan-ignore-next-line - This is a final class, safe to use new static()
return new static(
$container->get('analyze.helper')
);
Expand Down
8 changes: 7 additions & 1 deletion src/Form/AnalyzeSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
/**
* {@inheritdoc}
*
* @phpstan-param array<string, mixed> $form
* @param array<string, mixed> $form
* The form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @param-out array<string, mixed> $form
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$values = $form_state->cleanValues()->getValues();
Expand All @@ -137,6 +142,7 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
$this->config('analyze.settings')
->set('status', $settings)
->save();
// @phpstan-ignore-next-line - Parent method accepts array reference
parent::submitForm($form, $form_state);
}

Expand Down