Skip to content

Commit

Permalink
Clean up update script
Browse files Browse the repository at this point in the history
  • Loading branch information
robdekort committed Jan 24, 2024
1 parent 22fa491 commit 9ff839d
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions src/Updates/UpdateImagesBlueprintWithExemptToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,43 @@ public function update()
{
$file = base_path("resources/blueprints/assets/images.yaml");

if (File::exists($file)) {
$newField = [
'handle' => 'exempt_from_alt',
'field' => [
'inline_label' => "This image doesn't need an alt text.",
'default' => false,
'type' => 'toggle',
'display' => 'Exempt',
'icon' => 'toggle',
'listable' => 'hidden',
'instructions_position' => 'below',
'visibility' => 'visible',
'replicator_preview' => true,
'hide_display' => false,
'instructions' => "When enabled, this image won't show up in the control panel dashboard as an image that misses alt text. Images without an alt text will automatically be hidden for screen readers."
]
];

$blueprint = Yaml::parseFile($file);
$existingFields = Arr::get($blueprint, 'sections.main.fields');

if ($existingFields) {
$existingFields[] = $newField;

Arr::set($blueprint, 'sections.main.fields', $existingFields);
File::put($file, Yaml::dump($blueprint, 99, 2));

$this->console()->info('Added an exempt from alt toggle to the images blueprint in `resources/blueprints/assets/images.yaml`');
} else {
$this->console()->info("Couldn't add an exempt from alt toggle to the images blueprint in `resources/blueprints/assets/images.yaml`");
}
} else {
if (! File::exists($file)) {
$this->console()->info('Add an `exempt_from_alt` toggle field to any asset blueprints where you want this functionality.');

return;
}

$newField = [
'handle' => 'exempt_from_alt',
'field' => [
'inline_label' => "This image doesn't need an alt text.",
'default' => false,
'type' => 'toggle',
'display' => 'Exempt',
'icon' => 'toggle',
'listable' => 'hidden',
'instructions_position' => 'below',
'visibility' => 'visible',
'replicator_preview' => true,
'hide_display' => false,
'instructions' => "When enabled, this image won't show up in the control panel dashboard as an image that misses alt text. Images without an alt text will automatically be hidden for screen readers."
]
];

$blueprint = Yaml::parseFile($file);
$existingFields = Arr::get($blueprint, 'sections.main.fields');

if (! $existingFields) {
$this->console()->info("Couldn't add an exempt from alt toggle to the images blueprint in `resources/blueprints/assets/images.yaml`");

return;
}

$existingFields[] = $newField;

Arr::set($blueprint, 'sections.main.fields', $existingFields);
File::put($file, Yaml::dump($blueprint, 99, 2));

$this->console()->info('Added an exempt from alt toggle to the images blueprint in `resources/blueprints/assets/images.yaml`');
}
}

0 comments on commit 9ff839d

Please sign in to comment.