Jump to content

Trying to create field using API


chcs
 Share

Recommended Posts

After running this code in my module's __install() the template_id is not set. Any ideas why?  (The export contents from the template created and the one that I built with Admin are the same. Both exports have the template_id is set to mm_state. When I go to edit the field in Admin, the template is not showing on the Input tab and it doesn't show the template title on a page using the template that uses this field. Using processwire 3.0.98)

// mm_state
$field = $this->fields->get('mm_state');
if (!@$field->id) $field = new Field();
$field->type = $this->modules->get("FieldtypePage");
$field->name = 'mm_state';
$field->label = 'State';
$field->derefAsPage = 2;
$field->inputfield = "InputfieldSelect";
$this->fields->save($field);
$field->labelFieldName = 'title';
$field->template_id = 'mm_state';
$field->columnWidth = 100;
$field->required = true;
$this->fields->save($field);

Link to comment
Share on other sites

3 hours ago, chcs said:

Both exports have the template_id is set to mm_state

Just an FYI - the reason the template_id is set to the name of the template in the export is so it is translatable to another PW site where that template will likely have a different ID. This way the import process can use the supplied name to find and then set the local ID for that template.

  • 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...