pboivin
09/11/2021, 3:46 PMpboivin
09/11/2021, 3:47 PMjson_decode()
in your field helper method.agnonym
09/11/2021, 4:47 PMagnonym
09/11/2021, 5:08 PMgetFormFieldsHandleFieldsGroups()
function of the HandleFieldsGroups
Trait:
public function getFormFieldsHandleFieldsGroups($object, $fields)
{
foreach ($this->fieldsGroup as $group => $groupFields) {
if ($object->$group) {
//// BEFORE
$decoded_fields = json_decode($object->$group, true) ?? [];
//// AFTER
$casts = $object->getCasts();
if (array_key_exists($group, $casts) && $casts[$group] === 'array') {
$decoded_fields = $object->$group;
} else {
$decoded_fields = json_decode($object->$group, true) ?? [];
}
// In case that some field read the value through $item->$name
foreach ($decoded_fields as $field_name => $field_value) {
$object->setAttribute($field_name, $field_value);
}
$fields = array_merge($fields, $decoded_fields);
}
}
return $fields;
}
pboivin
09/11/2021, 5:21 PMpboivin
09/11/2021, 5:22 PM$translatedAttributes
and translated JSON fields on the base model doesn't feel ideal. I wonder what are the challenges of introducing support for JSON fields at the translation model level...agnonym
09/11/2021, 5:39 PMagnonym
09/11/2021, 7:01 PMhow_else
09/11/2021, 8:45 PMifox
09/11/2021, 8:50 PMstorage/logs
how_else
09/11/2021, 9:08 PMDefenestrația
09/12/2021, 1:08 AMpboivin
09/12/2021, 11:29 AMHandleJsonRepeaters
trait was found in this issue: https://github.com/area17/twill/issues/1060#issuecomment-888062137Alexander
09/13/2021, 8:17 AMifox
09/13/2021, 8:21 AMselect * from mediables where mediable_id = <your-product-id>
would give you rows that have the media id from the medias table as well as all the attachement information, like cropping values.Alexander
09/13/2021, 8:26 AMifox
09/13/2021, 8:28 AMmediable_type
column, i omitted that condition for simplicity but honestly you shouldn't write raw queries for thisAlexander
09/13/2021, 8:31 AMifox
09/13/2021, 8:31 AMAlexander
09/13/2021, 8:33 AMmediable_type
will be a hassle to work with, a lot of images are inside the blocks
type and I'll be having issues narrowing it down to specific types of tables.ifox
09/13/2021, 8:35 AMAlexander
09/13/2021, 8:37 AMifox
09/13/2021, 8:38 AMifox
09/13/2021, 8:39 AMAlexander
09/13/2021, 8:39 AMAlexander
09/13/2021, 8:40 AMSami
09/13/2021, 9:12 AMSami
09/13/2021, 9:16 AMphp
public function element()
{
return $this->belongsTo(Element::class);
}
Element:
php
public function microsite()
{
return $this->hasOne(Microsite::class);
}
In MicrositeRepository there is:
php
public function afterSave($object, $fields)
{
$this->updateBrowser($object, $fields, 'element');
parent::afterSave($object, $fields);
}
public function getFormFields($object)
{
$fields = parent::getFormFields($object);
$fields['browsers']['elements'] = $this->getFormFieldsForBrowser($object, 'elements');
return $fields;
}
And in Microsite form.blade.php I have this:
@formField('browser', [
'moduleName' => 'elements',
'name' => 'elements',
'label' => 'Element'
])
Sami
09/13/2021, 9:24 AM$this->getFormFieldsForBrowser($object, 'elements');
returns null