-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Studio1902\PeakTools\Updates; | ||
|
||
use Statamic\Support\Arr; | ||
use Illuminate\Support\Facades\File; | ||
use Symfony\Component\Yaml\Yaml; | ||
use Statamic\UpdateScripts\UpdateScript; | ||
|
||
class UpdateImagesBlueprintWithExemptToggle extends UpdateScript | ||
{ | ||
public function shouldUpdate($newVersion, $oldVersion) | ||
{ | ||
return $this->isUpdatingTo('4.4.0'); | ||
} | ||
|
||
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 { | ||
$this->console()->info('Add an `exempt_from_alt` toggle field to any asset blueprints where you want this functionality.'); | ||
} | ||
} | ||
} |