Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"drupal/entity_usage": "^2.0@beta",
"drupal/environment_indicator": "^4.0.25",
"drupal/field_group": "^4",
"drupal/generated_content": "^2",
"drupal/gin": "^4.0.6",
"drupal/gin_toolbar": "^2",
"drupal/google_tag": "^2.0.9",
Expand Down
58 changes: 57 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions scripts/custom/provision-20-generated-content.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
##
# Generate content for non-production environments.
#
# shellcheck disable=SC2086

set -eu
[ "${VORTEX_DEBUG-}" = "1" ] && set -x

# ------------------------------------------------------------------------------

info() { printf " ==> %s\n" "${1}"; }
task() { printf " > %s\n" "${1}"; }
note() { printf " %s\n" "${1}"; }

drush() { php -d memory_limit=2G vendor/bin/drush.php -y "$@"; }

GENERATED_CONTENT_SKIP="${GENERATED_CONTENT_SKIP:-0}"

info "Started generated content operations."

environment="$(drush php:eval "print \Drupal\core\Site\Settings::get('environment');")"
note "Environment: ${environment}"

# Perform operations based on the current environment.
if echo "${environment}" | grep -q -e dev -e ci -e local; then
if [ "${VORTEX_PROVISION_OVERRIDE_DB:-0}" = "1" ]; then

if [ "${GENERATED_CONTENT_SKIP}" = "1" ]; then
note "Skipping generation of content."
else
task "Enabling generated content module."
export GENERATED_CONTENT_CREATE=1
drush pm:enable -y do_generated_content
note "Generated content module enabled."
fi
else
note "Using existing database with existing content."
fi
else
note "Skipping generated content operations in production environment."
fi

info "Finished generated content operations."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: DrevOps Website Generated Content
type: module
description: 'Provides generated content for non-production environments.'
package: DrevOps
core_version_requirement: ^10.3 || ^11
dependencies:
- generated_content:generated_content
Comment on lines +6 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add missing do_base dependency declaration.

The module metadata currently omits do_base, even though this feature set assumes base content model availability. Without explicit dependency, enable/install order can break and generators can fail at runtime.

🔧 Proposed fix
 dependencies:
   - generated_content:generated_content
+  - do_base:do_base
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dependencies:
- generated_content:generated_content
dependencies:
- generated_content:generated_content
- do_base:do_base
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/modules/custom/do_generated_content/do_generated_content.info.yml` around
lines 6 - 7, The module metadata is missing the do_base dependency which can
break install/enable order; update the dependencies block in
do_generated_content.info.yml (the dependencies: list for the
do_generated_content module that currently contains
generated_content:generated_content) to include do_base (e.g., add
do_base:do_base or the appropriate do_base machine name entry) so that the
do_generated_content module declares and enforces the required base module at
install time.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Drupal\do_generated_content\Plugin\GeneratedContent;

use Drupal\generated_content\Attribute\GeneratedContent;
use Drupal\generated_content\Helpers\GeneratedContentAssetGenerator;
use Drupal\generated_content\Plugin\GeneratedContent\GeneratedContentPluginBase;

/**
* Generated files.
*/
#[GeneratedContent(
id: 'do_generated_content_file_file',
entity_type: 'file',
bundle: 'file',
weight: -10,
tracking: TRUE,
)]
class FileFile extends GeneratedContentPluginBase {

/**
* {@inheritdoc}
*/
public function generate(): array {
$entities = [];

$types = [
GeneratedContentAssetGenerator::ASSET_TYPE_JPG,
GeneratedContentAssetGenerator::ASSET_TYPE_PNG,
];

for ($i = 0; $i < 20; $i++) {
$type = $this->helper::randomArrayItem($types);
$width = $this->helper::randomBool() ? 1200 : 800;
$height = $this->helper::randomBool() ? 600 : 400;

$file = $this->helper::createFile($type, [
'width' => $width,
'height' => $height,
]);

$entities[] = $file;
$this->helper::log('Created file: %s', $file->getFilename());
Comment on lines +41 to +47
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add null check before using $file.

If helper::createFile() fails or returns null, calling $file->getFilename() on line 47 will cause a null pointer exception. The MediaCivicthemeImage plugin demonstrates the defensive pattern by checking if (!$file instanceof FileInterface).

🛡️ Proposed fix to add validation
       $file = $this->helper::createFile($type, [
         'width' => $width,
         'height' => $height,
       ]);
 
+      if ($file === NULL) {
+        continue;
+      }
+
       $entities[] = $file;
       $this->helper::log('Created file: %s', $file->getFilename());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$file = $this->helper::createFile($type, [
'width' => $width,
'height' => $height,
]);
$entities[] = $file;
$this->helper::log('Created file: %s', $file->getFilename());
$file = $this->helper::createFile($type, [
'width' => $width,
'height' => $height,
]);
if ($file === NULL) {
continue;
}
$entities[] = $file;
$this->helper::log('Created file: %s', $file->getFilename());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@web/modules/custom/do_generated_content/src/Plugin/GeneratedContent/FileFile.php`
around lines 41 - 47, Ensure you null-check and validate the result of
helper::createFile before using it: after calling $file =
$this->helper::createFile($type, [...]) verify that $file is an instance of
FileInterface (mirroring the MediaCivicthemeImage pattern) and only then push to
$entities and call $this->helper::log('Created file: %s', $file->getFilename());
otherwise skip logging/adding or handle the error path accordingly so no null
pointer occurs.

}

return $entities;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Drupal\do_generated_content\Plugin\GeneratedContent;

use Drupal\file\FileInterface;
use Drupal\generated_content\Attribute\GeneratedContent;
use Drupal\generated_content\Plugin\GeneratedContent\GeneratedContentPluginBase;
use Drupal\media\Entity\Media;

/**
* Generated image media entities.
*/
#[GeneratedContent(
id: 'do_generated_content_media_civictheme_image',
entity_type: 'media',
bundle: 'civictheme_image',
weight: 1,
tracking: TRUE,
)]
class MediaCivicthemeImage extends GeneratedContentPluginBase {

/**
* {@inheritdoc}
*/
public function generate(): array {
$entities = [];

for ($i = 0; $i < 10; $i++) {
$file = $this->helper::randomFile('jpg');

if (!$file instanceof FileInterface) {
$file = $this->helper::randomFile('png');
}

if (!$file instanceof FileInterface) {
continue;
}

$name = sprintf('Generated image %s', $i + 1);

$media = Media::create([
'bundle' => 'civictheme_image',
'name' => $name,
'field_c_m_image' => [
'target_id' => $file->id(),
'alt' => $this->helper::staticSentence(3),
],
]);

$media->save();
$entities[] = $media;

$this->helper::log('Created media: %s', $name);
}

return $entities;
}

}
Loading
Loading