neonbug / meexo-gallery
Gallery package for Meexo CMS
1.0.2
2022-10-23 19:19 UTC
Requires
- bkwld/croppa: ~4.0
- flowjs/flow-php-server: ^1.0.3
- neonbug/meexo-common: ^1.0
README
Use gallery images as data type in other modules
-
Open your module's model (e.g.
/Models/Shop.php
) and implement\Neonbug\Gallery\Traits\GalleryImagesTraitInterface
interface.Example:
<?php namespace App\Packages\Shop\Models;
class Shop extends \Neonbug\Common\Models\BaseModel implements \Neonbug\Gallery\Traits\GalleryImagesTraitInterface {
public $gallery_images = []; // keys are id languages, then field names
public static function getTableNameForGalleryImages() { return 'shop'; } // from GalleryImagesTraitInterface
public static function getUploadsFolderNameForGalleryImages() { return 'shop'; } // from GalleryImagesTraitInterface
-
Use trait
\Neonbug\Gallery\Traits\GalleryImagesTrait
in your module's ServiceProvider (e.g./Providers/ServiceProvider.php
.Example:
<?php namespace App\Packages\Shop\Providers;
class ServiceProvider extends \Neonbug\Common\Providers\BaseServiceProvider {
use \Neonbug\Gallery\Traits\GalleryImagesTrait;
-
Add a field (or multiple) with type
gallery_admin::add_fields.gallery_images
in your module's config file (e.g./config/shop.php
).Example:
<?php
return [
...
'add' => [
[
'name' => 'images',
'type' => 'gallery_admin::add_fields.gallery_images',
'value' => '',
],
],
...
];
-
To load images, use
getImages
method onGalleryRepository
. It returns a collection ofGalleryImage
objects.Example:
<?php
...
$images = App::make('\Neonbug\Gallery\Repositories\GalleryRepository')->getImages(
'shop', // table name
'images', // field name
$item->id_shop, // item id
null // language id (or null, if this field is language independent)
);
-
To display images in views, use
getPath
method onGalleryImage
to get the image path.Example:
@foreach ($images as $image)
<?php
$image_path = $image->getPath(
'shop', // table name
'images', //
$item->id_shop, // item id
0 // language id (or 0, if this field is language independent)
);
if (!file_exists($image_path))
{
continue;
}
?>
<img src="{!! Croppa::url($image_path, 420, 280) !!}" />
@endforeach
License
Available under the MIT license.