Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384<?php
/** * Splashing Images plugin for Craft CMS * * unsplash.com integration for Craft * * @link https://studioespresso.co * * @copyright Copyright (c) 2017 Studio Espresso */
namespace studioespresso\splashingimages;
use CraftCms\Cms\Asset\Data\Volume;use CraftCms\Cms\Cp\Data\NavItem;use CraftCms\Cms\Plugin\Plugin;use CraftCms\Cms\Plugin\PluginSettings;use CraftCms\Cms\Support\Facades\Volumes;use CraftCms\Cms\Ui\Controls\Choice;use CraftCms\Cms\Ui\Controls\Text;use CraftCms\Cms\Ui\Nodes\Field;use CraftCms\Cms\Ui\Ui;use CraftCms\Cms\Ui\UiContext;
use function CraftCms\Cms\t;
/** * @author Studio Espresso * * @since 1.0.0 * * @method Settings getSettings() */class SplashingImages extends Plugin{ /** Craft 5 users must be on 5.0.4 first: it converts the volume setting from an ID to a handle */ public string $minVersionRequired = '5.0.4';
protected array $styles = [ __DIR__.'/../resources/dist/css/SplashingImages.css' => 'css/SplashingImages.css', ];
protected array $scripts = [ __DIR__.'/../resources/dist/js/splashing-images.js' => 'js/splashing-images.js', ];
public function boot(): void { $this->app->singleton(Settings::class, fn () => $this->getSettings()); }
protected static function createSettings(): ?PluginSettings { return new Settings; }
public function getCpNavItem(): NavItem|array|null { return new NavItem() ->label($this->getSettings()->pluginLabel ?: 'Unsplash Images') ->href($this->handle) ->iconSvg(file_get_contents($this->getResourcesPath().'/icon-mask.svg')); }
public function settingsUi(UiContext $context = new UiContext): ?Ui { $volumes = Volumes::getAllVolumes() ->map(fn (Volume $volume) => ['label' => $volume->name, 'value' => $volume->handle]) ->values() ->all();
return Ui::make([ Field::make(t('Plugin label', category: 'splashing-images'), Text::make('pluginLabel')) ->instructions(t('You can give the plugin in different name in the CP navigation here', category: 'splashing-images')), Field::make(t('Volume', category: 'splashing-images'), Choice::make('destination')->options($volumes)->placeholder(t('Select a volume', category: 'splashing-images'))) ->instructions(t('Select the volume where your images should be save', category: 'splashing-images')) ->required(), Field::make(t('Folder', category: 'splashing-images'), Text::make('folder')) ->instructions('path/to/subfolder'), ]); }}