v2-hub icon indicating copy to clipboard operation
v2-hub copied to clipboard

Custom ReplicatorFieldtype config Object's set attribute is not an Array anymore.

Open josewhitetower opened this issue 6 years ago • 1 comments

Describe the bug When creating a custom ReplicatorFieldtype the sets will not be correctly shown. See Scrennshot1

  1. Screenshot 1 localhost_services_statamic_cp_addons_content-store_edit_slideshow_1f220cdf-544a-4d08-9597-f23c8dec6dc0 2 It is produced because the custom fieldtype vue component receive from the .yaml File a config object which has a sets 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

  1. Screenshot 2 bildschirmfoto 2018-09-26 um 13 55 33

Expected behavior

It is expected that the config object's set attribute an array is. When type set to default replicator See Screenshot3

  1. Screenshot 3 bildschirmfoto 2018-09-26 um 13 50 02

Environment details (please complete the following information):

  • Statamic Version [2.10.4]
  • Addons installed: Using our own addon

Additional context

  1. This is a secondary fieldtype.
  2. 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.
  3. This custom fieldtype vue component has inside the replicator-fieldtype and receives the props data, 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>
  1. 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);
    }
}

josewhitetower avatar Sep 26 '18 12:09 josewhitetower

How likely is this going to get changed? We are trying to figure out if we should roll our own "arrayfication".

eike-hass avatar Nov 28 '18 11:11 eike-hass