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
-
Add new method in the facade
\PSMFields\Facades\PSMFieldsMetaboxand InterfacePSMFields\Contracts\FacadeExternalUsageMethodsInterfacenamedadd{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
addFieldand return$thisso we can chain the methods later. - Example: For this field we would only use
$name,$title, and$descriptionbut 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; }``` - All the field methods in the Facade must only add to fields array using the Facade method
-
Add new class in the Namespace
\PSMFields\Controllers\Fieldswith the name:{field type}FieldControllerand extend the\PSMFields\Controllers\FieldsControllerabstract 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}
- For the field wrapper please use css classes
- Please keep the same css naming structure.
-
Please make sure that all newly added classes and methods contain PHP Doc comments
-
Write unit tests (still not implemented)
-
Add info or changes to the README.md file
-
Change library version in the
psm-fields/autoload.phpfile and\PSMFields\Config\BaseConfigproperty.