Library development (Adding new field) - AleksandarPredic/psm-fields GitHub Wiki

Library development

This section contains instructions for the devs that are working on this library.

Add new field steps

  1. Add new method in the facade \PSMFields\Facades\PSMFieldsMetabox and Interface PSMFields\Contracts\FacadeExternalUsageMethodsInterface named add{field type}Field. For example please check the existing method: addInputTextField.

    • All the field methods in the Facade must only add to fields array using the Facade method addField and return $this so we can chain the methods later.
    • Example: For this field we would only use $name, $title, and $description but we need to comply with the add field method and pass also other params that we don't use in our example.
     public function add{fieldType}Field(
         string $name,
         string $title,
         string $description = ''
     ) {
         $this->addField(
             [
                 'class_name'  => {fieldType}FieldController::class,
                 'name'        => $this->sanitizeFieldName($name),
                 'title'       => $title,
                 'description' => $description,
                 'args'        => [] // Not needed for example field, but it is needed for select field to pass options
             ]
         );
    
         return $this;
     }```
    
    
  2. Add new class in the Namespace \PSMFields\Controllers\Fields with the name: {field type}FieldController and extend the \PSMFields\Controllers\FieldsController abstract class. Use the parameters you defined in step 1.

    • Please keep the same css naming structure.
      • For the field wrapper please use css classes psmfields__field psmfields__field--{field type}.
      • For the field css id and css class
      • Add unique string to the label for and input id attribute to avoid browser complaining about multiple ids please use psmfields__select-{name parameter}
  3. Please make sure that all newly added classes and methods contain PHP Doc comments

  4. Write unit tests (still not implemented)

  5. Add info or changes to the README.md file

  6. Change library version in the psm-fields/autoload.php file and \PSMFields\Config\BaseConfig property.