Themosis\Field\Fields\FieldBuilder::setType PHP Method

setType() protected method

If no type is defined, default to an array containing the 'image' mime type only. Need to "serialize" the array for output as a string value. We can use a separated list with commas.
protected setType ( )
    protected function setType()
    {
        // Retrieve allowed WordPress mime types.
        // If none are defined, this will be the default types.
        // Users will be able to add any media file.
        $allowed = $this->getAllowedMimeTypes();
        $features = $this['features'];
        // User has defined media type(s)
        // It might be a string or an array.
        if (isset($features['type'])) {
            $type = $features['type'];
            // Isset... Check if is a string... If it is, turn it into an array.
            if (is_string($type)) {
                $type = [$type];
            }
            // $type is an array, let's check its values.
            $type = array_intersect($type, $allowed);
            if (!empty($type)) {
                $features['type'] = $type;
            } else {
                $features['type'] = $allowed;
            }
        } else {
            $features['type'] = $allowed;
        }
        // "Serialize" the $features['type'] value. Build a comma separated list of types.
        $features['type'] = implode(',', $features['type']);
        // Set the features back.
        $this['features'] = $features;
        // Set the data-type attribute.
        $atts = $this['atts'];
        $atts['data-type'] = $this['features']['type'];
        $this['atts'] = $atts;
    }