Back to Installer class

Method getParams

public string
getParams
()
Method to parse the parameters of an extension, build the JSON string for its default parameters, and return the JSON string.
Returns
  • string JSON string of parameter values
Since
  • 3.1
-
  • This method must always return a JSON compliant string
Class: Installer
Project: Joomla

Method getParams - Source code

/**
 * Method to parse the parameters of an extension, build the JSON string for its default parameters, and return the JSON string.
 *
 * @return  string  JSON string of parameter values
 *
 * @since   3.1
 * @note    This method must always return a JSON compliant string
 */
public function getParams()
{
    // Validate that we have a fieldset to use
    if (!isset($this->manifest->config->fields->fieldset)) {
        return '{}';
    }
    // Getting the fieldset tags
    $fieldsets = $this->manifest->config->fields->fieldset;
    // Creating the data collection variable:
    $ini = array();
    // Iterating through the fieldsets:
    foreach ($fieldsets as $fieldset) {
        if (!\count($fieldset->children())) {
            // Either the tag does not exist or has no children therefore we return zero files processed.
            return '{}';
        }
        // Iterating through the fields and collecting the name/default values:
        foreach ($fieldset as $field) {
            // Check against the null value since otherwise default values like "0"
            // cause entire parameters to be skipped.
            if (($name = $field->attributes()->name) === null) {
                continue;
            }
            if (($value = $field->attributes()->default) === null) {
                continue;
            }
            $ini[(string) $name] = (string) $value;
        }
    }
    return json_encode($ini);
}