Jump to content

Fieldtype YAML


owzim
 Share

Recommended Posts

3 hours ago, Pixrael said:

Just installed in PW 3.0.61 .. when add new field type YAML and save I get the following error:

Session: Warning (showIf): dependency field 'contentType' is not present in this form. (ProcessFieldEdit)

This is because the module extends Fieldtype Textarea but removes certain config inputfields (including contentType) that are not to be used with Fieldtype YAML. I'm guessing that the core Fieldtype Textarea has added an inputfield dependency for contentType since the Fieldtype YAML module was created, hence the warning.

@owzim, maybe the module could set the unused config inputfields to hidden rather than not including them in the field config at all?

foreach($parentInputfields as $inputfield) {
    if(in_array($inputfield->name, $forbidden)) {
        $inputfield->collapsed = Inputfield::collapsedHidden;
    }
    $inputfields->append($inputfield);
}

 

  • Like 4
Link to comment
Share on other sites

  • 2 months later...
On 2017-4-29 at 7:46 AM, Robin S said:

@owzim, maybe the module could set the unused config inputfields to hidden rather than not including them in the field config at all?


foreach($parentInputfields as $inputfield) {
    if(in_array($inputfield->name, $forbidden)) {
        $inputfield->collapsed = Inputfield::collapsedHidden;
    }
    $inputfields->append($inputfield);
}

@owzim Hi, any chance of applying this fix? Thank you in advance.

Link to comment
Share on other sites

I have just tested @owzim's other great module InputfieldAceExtended which works perfectly if we want to use syntax highlighting for YAML. However, @Robin S's suggestion to fix the error changes the Details Tab, making it impossible to configure the InputField Type as seen in the screenshots below:

original:

fieldtype-yaml-original.png.035a55d46e5cf653e207bc063f63c6a6.png

after applying the suggestion:

Spoiler

fieldtype-yaml-robins-suggestion.thumb.png.62c64db09d52359f032913f2fe601429.png

 

Link to comment
Share on other sites

  • 2 years later...

Does anyone know how to save an Array or a WireArray back to the YAML field in the page? In the source code I saw some functions for "Dump", but I don't know which one would be the right one, or how to use it.

Link to comment
Share on other sites

AFAIK the module does not provide any class to convert array to YAML. the purpose of the module is an inputfield, for YAML formatted text, and has options for output into various formats, but it does not provide any interface for Array to YAML. If you convert your array to JSON, you may be able to find an online converted that can generate YAML from JSON...

Link to comment
Share on other sites

On 8/6/2019 at 10:10 AM, Pixrael said:

Does anyone know how to save an Array or a WireArray back to the YAML field in the page?

As stated in the module readme, FieldtypeYaml uses a namespaced version of Spyc. And the examples for Spyc show how to dump an array to YAML: https://github.com/mustangostang/spyc/blob/master/examples/yaml-dump.php

So to reproduce that example using the namespaced Spyc bundled with FieldtypeYaml:

// Init the module so Spyc gets loaded
$modules->get('FieldtypeYaml');

// Some array data
$array[] = 'Sequence item';
$array['The Key'] = 'Mapped value';
$array[] = array('A sequence','of a sequence');
$array[] = array('first' => 'A sequence','second' => 'of mapped values');
$array['Mapped'] = array('A sequence','which is mapped');
$array['A Note'] = 'What if your text is too long?';
$array['Another Note'] = 'If that is the case, the dumper will probably fold your text by using a block. Kinda like this.';
$array['The trick?'] = 'The trick is that we overrode the default indent, 2, to 4 and the default wordwrap, 40, to 60.';
$array['Old Dog'] = "And if you want\n to preserve line breaks, \ngo ahead!";
$array['key:withcolon'] = "Should support this to";

// Dump to YAML with some (optional) custom indent and wordwrap settings
$yaml = \owzim\FieldtypeYaml\Vendor\Spyc::YAMLDump($array,4,60);

// See the result in a Tracy dump
bdb($yaml, 'yaml');

2019-08-13_204912.png.5aa6f7b083938bb6a1d6f65401601bd5.png

You can convert a WireArray to a plain array with getArray().

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...