Jump to content

create pagearray field with api? (multipage select field?)


Recommended Posts

Posted

Quick question for anyone who is familiar with it..

If creating a new text field with the api looks something like this:

$nf = new Field();  

$nf->type = $this->modules->get(FieldTypeText);

$nf->save();

Then how would I create that field which allows me to select multiple pages (which module do I get and set type as)

I usually just choose from modules under wire/modules/Fieldtype. But, in this case I'm not sure which one it is.

I know I could dereference any pagearray as a string and save the pipe delemited string to the text field, but I'd liek to have the pageselect functionality in the admin.

Thanks In Advance

Posted
$f = new Field();
$f->type = $this->modules->get("FieldtypePage");
$f->name = 'mypageselect';
$f->label = 'Select Page';
$f->derefAsPage = FieldtypePage::derefAsPageOrNullPage;
$f->inputfield = 'InputfieldPageListSelect';
$f->save();
 

or

$f->derefAsPage = FieldtypePage::derefAsPageArray;
$f->inputfield = 'InputfieldAsmSelect';

etc

  • Like 3
Posted

The module is FieldtypePage. I'm not sure how to configure the field options...

I'm trying to do my field creations with the api but I never know how to configure the field options either. Is there any documentation for this?

$f = new Field();
$f->type = $this->modules->get("FieldtypePage");
$f->name = 'mypageselect';
$f->label = 'Select Page';
$f->derefAsPage = FieldtypePage::derefAsPageOrNullPage;
$f->inputfield = 'InputfieldPageListSelect';
$f->save();
 

or

$f->derefAsPage = FieldtypePage::derefAsPageArray;
$f->inputfield = 'InputfieldAsmSelect';

etc

thanks, wow I would have never of guessed.

Posted

Theres a documentation directly in core. Just look at what options a fieldtype has by looking at the code in wire modules.

Posted

I didn't see the second example before... Soma, didn't you edit your answer?

It's already there in the first example...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...