List custom fields to duplicate

AllRems

New Member
Hi, i have one list with 3 default custom fields (email, first name, last name) (image)

I add 6 other custom fields (geocity, geocountry....)

i want this 9 fields to be the default for all lists that i create

Any idea how to do this?
thank you
 

Attachments

  • capture-ecran 29.jpg
    capture-ecran 29.jpg
    421 KB · Views: 5
The only way to do this is via custom coding, let me get the code sample for you, gimme 10 mins.
 
Create a file called init-custom.php in the /apps/ folder, with a content like this:
PHP:
<?php


Yii::app()->hooks->addAction('after_list_created_list_default_fields', function ($params) {
  
    $geoCityType = ListFieldType::model()->findByAttributes([
        'identifier' => 'geocity',
    ]);
    $model = new ListField();
    $model->list_id    = $params->list->list_id;
    $model->type_id    = $geoCityType->type_id;
    $model->label      = 'City';
    $model->tag        = 'CITY';
    $model->required   = ListField::TEXT_NO;
    $model->sort_order = $params->lastSortOrder++;
    $model->save();

    $geoStateType = ListFieldType::model()->findByAttributes([
        'identifier' => 'geostate',
    ]);
    $model = new ListField();
    $model->list_id         = $params->list->list_id;
    $model->type_id         = $geoStateType->type_id;
    $model->label           = 'State';
    $model->tag             = 'STATE';
    $model->required        = ListField::TEXT_NO;
    $model->sort_order      = $params->lastSortOrder++;
    $model->save();

    $geoCountryType = ListFieldType::model()->findByAttributes([
        'identifier' => 'geocountry',
    ]);
    $model = new ListField();
    $model->list_id         = $params->list->list_id;
    $model->type_id         = $geoCountryType->type_id;
    $model->label           = 'Country';
    $model->tag             = 'COUNTRY';
    $model->required        = ListField::TEXT_NO;
    $model->sort_order      = $params->lastSortOrder++;
    $model->save();
});
The above code says that each new list will get a geocity, geostate and geocountry fields.
You can add more if needed be, you can use following identifiers:
Screenshot 2020-12-16 at 14.33.04.png
So if you'd need to add a url field for example, you would add:
PHP:
$urlType = ListFieldType::model()->findByAttributes([
    'identifier' => 'url',
]);
$model = new ListField();
$model->list_id         = $params->list->list_id;
$model->type_id         = $urlType->type_id;
$model->label           = 'Website url';
$model->tag             = 'URL';
$model->required        = ListField::TEXT_NO;
$model->sort_order      = $params->lastSortOrder++;
$model->save();

Best of luck.
 
Back
Top