pauldwight
pauldwight
TCTwill CMS
Created by Strife on 9/20/2024 in #👊support
Seeding into Modules with Media
Yes you can. This should get you going - this is what I use on a Singleton Model where we have the following mediaParams set:
public $mediasParams = [
'cover' => [
'default' => [
[
'name' => 'default',
'ratio' => 16 / 9,
],
],
],
];
public $mediasParams = [
'cover' => [
'default' => [
[
'name' => 'default',
'ratio' => 16 / 9,
],
],
],
];
$repo = app(HomepageRepository::class);

$page = $repo->create([
'title' => 'Home page title',
'published' => true,
]);

// Handle Media
// 1. Get Disk
$disk = Config::get('twill.media_library.disk');
$filename = 'hero-image.png';
$filePath = database_path('seeders/images/') . $filename;
$uuid = Str::uuid();
// Get image size
list($w, $h) = getimagesize($filePath);

// Store image
Storage::disk($disk)->put($uuid . '/' . $filename, file_get_contents($filePath));
$media = Media::create([
'uuid' => $uuid . '/' . $filename,
'filename' => $filename,
'caption' => '',
'alt_text' => '',
'width' => $w,
'height' => $h,
]);

// Calculate the Ratio and handle crop params
$mediaRole = 'cover';
$mediaCrop = 'default';
$cropParams = $page->getMediasParams()[$mediaRole][$mediaCrop][0];
$originalRatio = $w / $h;
if ($cropParams['ratio'] === 0) {
$crop_w = $w;
$crop_h = $h;
$crop_x = 0;
$crop_y = 0;
} elseif ($originalRatio <= $cropParams['ratio']) {
$crop_w = $w;
$crop_h = floor($w / $cropParams['ratio']);
$crop_x = 0;
$crop_y = floor(($h - $crop_h) / 2);
} else {
$crop_w = floor($h * $cropParams['ratio']);
$crop_h = $h;
$crop_x = floor(($w - $crop_w) / 2);
$crop_y = 0;
}

// Attach media to model
$page->medias()->attach($media->id, [
'metadatas' => '{}',
'role' => $mediaRole,
'crop_x' => $crop_x,
'crop_y' => $crop_y,
'crop_w' => $crop_w,
'crop_h' => $crop_h,
'crop' => $mediaCrop,
'ratio' => $mediaCrop,
]);
$repo = app(HomepageRepository::class);

$page = $repo->create([
'title' => 'Home page title',
'published' => true,
]);

// Handle Media
// 1. Get Disk
$disk = Config::get('twill.media_library.disk');
$filename = 'hero-image.png';
$filePath = database_path('seeders/images/') . $filename;
$uuid = Str::uuid();
// Get image size
list($w, $h) = getimagesize($filePath);

// Store image
Storage::disk($disk)->put($uuid . '/' . $filename, file_get_contents($filePath));
$media = Media::create([
'uuid' => $uuid . '/' . $filename,
'filename' => $filename,
'caption' => '',
'alt_text' => '',
'width' => $w,
'height' => $h,
]);

// Calculate the Ratio and handle crop params
$mediaRole = 'cover';
$mediaCrop = 'default';
$cropParams = $page->getMediasParams()[$mediaRole][$mediaCrop][0];
$originalRatio = $w / $h;
if ($cropParams['ratio'] === 0) {
$crop_w = $w;
$crop_h = $h;
$crop_x = 0;
$crop_y = 0;
} elseif ($originalRatio <= $cropParams['ratio']) {
$crop_w = $w;
$crop_h = floor($w / $cropParams['ratio']);
$crop_x = 0;
$crop_y = floor(($h - $crop_h) / 2);
} else {
$crop_w = floor($h * $cropParams['ratio']);
$crop_h = $h;
$crop_x = floor(($w - $crop_w) / 2);
$crop_y = 0;
}

// Attach media to model
$page->medias()->attach($media->id, [
'metadatas' => '{}',
'role' => $mediaRole,
'crop_x' => $crop_x,
'crop_y' => $crop_y,
'crop_w' => $crop_w,
'crop_h' => $crop_h,
'crop' => $mediaCrop,
'ratio' => $mediaCrop,
]);
4 replies
TCTwill CMS
Created by Strife on 9/13/2024 in #👊support
Trying to access file in setting
Hi @Strife You can get the file using the below approach
$brochureFile = A17\Twill\Facades\TwillAppSettings::getGroupDataForSectionAndName('site-settings', 'brochure');
// Below will return the URL
$brochureFile->file('single_file');
$brochureFile = A17\Twill\Facades\TwillAppSettings::getGroupDataForSectionAndName('site-settings', 'brochure');
// Below will return the URL
$brochureFile->file('single_file');
If you file isn't being saved in the settings then you need to make sure that you have included the single_file in your twill config
return [
'block_editor' => [
'crops' => [
...
],
'files' => ['single_file']
]
];
return [
'block_editor' => [
'crops' => [
...
],
'files' => ['single_file']
]
];
4 replies
TCTwill CMS
Created by Leonardo on 8/19/2024 in #👊support
Missing preview view,
I think the preview file is singular so leave the module name like you had it but just change the preview blade file to services.post.blade.php
6 replies
TCTwill CMS
Created by Leonardo on 8/19/2024 in #👊support
Missing preview view,
looks like you have created a file with services.posts.blade.php rather than services.post.blade.php - note the 'posts' and 'post' from the initial error message
6 replies
TCTwill CMS
Created by Huy Tớn on 3/21/2024 in #👊support
Save images in multple sizes for responsive?
The returned url should include params. e.g. http://domaintest/img/uuid-for-image/image-file-name.jpg?fm=jpg&amp;q=80&amp;fit=max&amp;crop=500%2C500%2C0%2C0 Glide is just an on-demand image manipulation library. It has requirements like GD library
13 replies
TCTwill CMS
Created by Huy Tớn on 3/21/2024 in #👊support
Save images in multple sizes for responsive?
Sorry - there is 1 image uploaded, the original, the defined crops will then be saved in the db table (as you can see). Your frontend then requests the crop you want e.g.
php $image->image('opening_banner','mobile')
php $image->image('opening_banner','mobile')
This image url contains the crop details and gets passed to the Image Rendering Service - default will be Glide and returns the cropped image
13 replies
TCTwill CMS
Created by Huy Tớn on 3/21/2024 in #👊support
Save images in multple sizes for responsive?
The crops are generated when it is requested rather than on upload
13 replies
TCTwill CMS
Created by Huy Tớn on 3/21/2024 in #👊support
Save images in multple sizes for responsive?
You can also check out the Twill Image package (https://github.com/area17/twill-image) for art-directed images
13 replies
TCTwill CMS
Created by Huy Tớn on 3/21/2024 in #👊support
Save images in multple sizes for responsive?
Hi @Huy Tớn Yes you can define whatever crops you want for an image. I generally use this where we want to use the same image for Desktop or Mobile but don't want to load the larger image on smaller screen sizes. Crops can be defined in the Model
public $mediasParams = [
'openingImage' => [
'desktop' => [
[
'name' => 'Desktop',
'ratio' => 16 / 9,
],
],
],
];
public $mediasParams = [
'openingImage' => [
'desktop' => [
[
'name' => 'Desktop',
'ratio' => 16 / 9,
],
],
],
];
Then it's up to you how you want to render or make use of this in your frontend. This is a good article on options for responsive images - https://css-tricks.com/a-guide-to-the-responsive-images-syntax-in-html/
13 replies
TCTwill CMS
Created by Aidas on 1/2/2024 in #👊support
Some fresh vibes would be nice :))
Thanks @ifox would be interesting to hear a bit more about your plans for the collaboration features whether that potentially includes some sort of content workflow (approval/review of content) or something else
6 replies
TCTwill CMS
Created by siașamaideparte on 12/1/2023 in #👊support
Route [admin.password.reset.link] not defined on upgrade from 2.x to 3
Hey @siașamaideparte Twill3 renamed the base from 'admin' to 'twill' - perhaps you have a view cached still?
4 replies
TCTwill CMS
Created by Mateo on 8/14/2023 in #👊support
twill metadata
@alwynWymeersch do you have the mediaParams set in your model?
public $mediasParams = [
'cover' => [
'default' => [
[
'name' => 'default',
// 'ratio' => 16 / 9,
],
],
],
];
public $mediasParams = [
'cover' => [
'default' => [
[
'name' => 'default',
// 'ratio' => 16 / 9,
],
],
],
];
16 replies
TCTwill CMS
Created by Mateo on 8/14/2023 in #👊support
twill metadata
Okay - the blade file is also including the fieldset so you can remove that part from your getForm() method so something like this...
$form->add(
BladePartial::make()->view('twill.fields.metadata')
->withAdditionalParams([
'metadata_card_type_options' => config('metadata.card_type_options'),
'metadata_og_type_options' => config('metadata.opengraph_type_options'),
])
);
$form->add(
BladePartial::make()->view('twill.fields.metadata')
->withAdditionalParams([
'metadata_card_type_options' => config('metadata.card_type_options'),
'metadata_og_type_options' => config('metadata.opengraph_type_options'),
])
);
16 replies
TCTwill CMS
Created by Mateo on 8/14/2023 in #👊support
twill metadata
It looks like you have 2 field sets somehow. Can you share your getForm function and the partial blade include?
16 replies
TCTwill CMS
Created by Mateo on 8/14/2023 in #👊support
twill metadata
We use it like this for Twill3
public function getForm(TwillModelContract $model): Form
{
$form = parent::getForm($model);

// publish the twill-metadata view then pass in the additional data from the config - we tend to have the SEO in it's own fieldset hence the below.
$form->addFieldset(
Fieldset::make()->title('SEO')->id('metadata')
->fields([
BladePartial::make()->view('twill.fields.metadata')
->withAdditionalParams([
'metadata_card_type_options' => config('metadata.card_type_options'),
'metadata_og_type_options' => config('metadata.opengraph_type_options'),
])
])
);

return $form;
}
public function getForm(TwillModelContract $model): Form
{
$form = parent::getForm($model);

// publish the twill-metadata view then pass in the additional data from the config - we tend to have the SEO in it's own fieldset hence the below.
$form->addFieldset(
Fieldset::make()->title('SEO')->id('metadata')
->fields([
BladePartial::make()->view('twill.fields.metadata')
->withAdditionalParams([
'metadata_card_type_options' => config('metadata.card_type_options'),
'metadata_og_type_options' => config('metadata.opengraph_type_options'),
])
])
);

return $form;
}
16 replies
TCTwill CMS
Created by kallefrombosnia on 6/14/2023 in #👊support
Twill navigation group
@kallefrombosnia instead of using the toExternalUrl I would personally set it the forModule('albums') for your primary Music link - otherwise i do the same as what you have done
10 replies
TCTwill CMS
Created by lazydog on 5/19/2023 in #👊support
Third Level Categories
By default the nestedItemsDepth is set to 1 - you can override this in your Twill Controller by adding the following protected $nestedItemsDepth = 2;
4 replies
TCTwill CMS
Created by thelongestsigh on 5/4/2023 in #👊support
New module item error
Most likely you haven't included the following in your model
public $mediasParams = [];
public $mediasParams = [];
See https://github.com/cwsdigital/twill-metadata/issues/23
6 replies
TCTwill CMS
Created by thelongestsigh on 5/4/2023 in #👊support
New module item error
which metadata package?
6 replies