v2-hub
v2-hub copied to clipboard
Custom ReplicatorFieldtype config Object's set attribute is not an Array anymore.
Describe the bug When creating a custom ReplicatorFieldtype the sets will not be correctly shown. See Scrennshot1
- Screenshot 1
It is produced because the custom fieldtype vue component receive from the .yaml File a
config
object which has asets
attribute that is an object, when actually an array is expected. Example:
slides:
type: myownaddon.custom_replicator
sets:
set1:
fields: ...
set2:
fields: ...
Result: See Screnshot2
- Screenshot 2
Expected behavior
It is expected that the config object's set attribute an array is. When type set to default replicator
See Screenshot3
- Screenshot 3
Environment details (please complete the following information):
- Statamic Version [2.10.4]
- Addons installed: Using our own addon
Additional context
- This is a secondary fieldtype.
- When replacing the default replicator fieldtype in the .yaml file, the config.sets is an array as expected. The same happens with bard fieldtype. And both show the sets correctly.
- This custom fieldtype vue component has inside the
replicator-fieldtype
and receives the propsdata
,config
,name
directly.
<template>
<replicator-fieldtype
v-ref:replicator
:data.sync="data"
:config="config"
:name="name"
>
</replicator-fieldtype>
</template>
<script>
export default {
name: 'CustomReplicator',
mixins: [window.Fieldtype],
ready() {
console.log(this.config);
},
};
</script>
<style>
</style>
- The custom Replicator .php class extends from
ReplicatorFieldtype
:
<?php
namespace Statamic\Addons\MyOwnAddon;
use Statamic\Addons\Replicator\ReplicatorFieldtype;
class CustomReplicatorFieldtype extends ReplicatorFieldtype
{
/**
* The blank/default value
*
* @return string
*/
public function blank()
{
return parent::blank();
}
/**
* Pre-process the data before it gets sent to the publish page
*
* @param mixed $data
* @return string
*/
public function preProcess($data)
{
return parent::preProcess($data);
}
/**
* Process the data before it gets saved
*
* @param mixed $data
* @return string
*/
public function process($data)
{
return parent::process($data);
}
}
How likely is this going to get changed? We are trying to figure out if we should roll our own "arrayfication".