class ParameterForm in Forena Reports 8
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\forena\Form\ParameterForm uses FrxAPI
 
 
Expanded class hierarchy of ParameterForm
1 file declares its use of ParameterForm
- TestingAppService.php in tests/
src/ Unit/ Mock/ TestingAppService.php  
File
- src/
Form/ ParameterForm.php, line 18  
Namespace
Drupal\forena\FormView source
class ParameterForm extends FormBase {
  use FrxAPI;
  public function getFormID() {
    return 'forena_parameter_form';
  }
  public function buildForm(array $form, FormStateInterface $form_state, $parameters = NULL) {
    $parms = $_GET;
    //$storage = $form_state->getStorage();
    // Set menu parms
    $menu_parms = $this
      ->getDataContext('menu-parms');
    if ($menu_parms) {
      $storage['menu-parms'] = $menu_parms;
    }
    // Set Descriptors
    $values = $form_state
      ->getValues();
    $collapse = isset($attributes['collapsed']) ? $attributes['collapsed'] : FALSE;
    if ($values) {
      $collapse = FALSE;
      $parms = array_merge($parms, $values['params']);
      // In the case of ahah, we need to restore menu parameters from the form state.
      if (isset($storage['menu-parms'])) {
        $menu_parms = $storage['menu-parms'];
        $parms = array_merge($menu_parms, $parms);
      }
      $this
        ->app()
        ->alter('forena_parameters', $report_name, $parms);
      $this
        ->pushData($parms, 'parm');
    }
    $template = @$attributes['template'];
    $collapsible = isset($attributes['collapsible']) ? $attributes['collapsible'] : TRUE;
    $title = isset($attributes['title']) ? $attributes['title'] : $this
      ->t('Parameters');
    $submit_value = isset($attributes['submit']) ? $attributes['submit'] : $this
      ->t('Submit');
    unset($parms['q']);
    $form = array();
    if ($parameters) {
      $this
        ->app()
        ->alter('forena_parameters', $report_name, $parms);
      if ($parameters) {
        $form['parms'] = array(
          '#tree' => TRUE,
          '#title' => $title,
          '#type' => 'details',
          '#collapsible' => $collapsible,
          '#collapsed' => $collapse,
          '#prefix' => '<div id="parameters-wrapper">',
          '#suffix' => '</div>',
        );
        foreach ($parameters as $node) {
          $add_null = FALSE;
          $list = array();
          $disabled = FALSE;
          $label = @(string) $node['label'];
          $id = @(string) $node['id'];
          $data_source = @(string) $node['data_source'];
          $data_field = @(string) $node['data_field'];
          $class = @(string) $node['class'];
          $type = @(string) $node['type'];
          $option_str = @(string) $node['options'];
          $options = array();
          if ($option_str) {
            parse_str($option_str, $options);
          }
          if (isset($parms[$id])) {
            $value = $parms[$id];
            $multi_value = (array) $parms[$id];
          }
          else {
            $value = @(string) $node['default'];
            if (strpos($value, '|') !== FALSE) {
              $multi_value = explode('|', $value);
            }
            elseif ($value) {
              $multi_value = (array) $value;
            }
            else {
              $multi_value = array();
            }
          }
          $desc = @(string) $node['desc'];
          $label_field = @(string) $node['label_field'];
          @(strcmp((string) $node['require'], "1") == 0) ? $required = TRUE : ($required = FALSE);
          $ctl_attrs = array();
          //returned values filtered against data_field attr.
          if ($data_source) {
            $list = DataManager::instance()
              ->dataBlockParams($data_source, $data_field, $label_field);
            if (!$required && $add_null) {
              $list = array(
                '' => '',
              ) + $list;
            }
          }
          //Determine the form element type to be displayed
          //If select or radios is chosen then begin a $list array for display values.
          $multiselect = FALSE;
          $ajax = FALSE;
          $add_null = FALSE;
          switch ($type) {
            case 'multiselect':
              $type = 'select';
              $multiselect = TRUE;
              $value = $multi_value;
              break;
            case 'multiselectajax':
              $type = 'select';
              $multiselect = TRUE;
              $value = $multi_value;
              $ajax = TRUE;
              break;
            case 'checkboxes':
              $value = $multi_value;
              break;
            case 'selectajax':
              $ajax = TRUE;
              $type = 'select';
              $add_null = TRUE;
              break;
            case 'select':
              $add_null = TRUE;
              break;
            case 'date_text':
            case 'date_select':
            case 'date_popup':
              $options['date_format'] = @$options['date_format'] ? $options['date_format'] : 'Y-m-d';
              $ctl_attrs['#date_format'] = $options['date_format'];
              if ($value) {
                $datetime = @strtotime($value);
                if ($datetime) {
                  $value = date('Y-m-d h:i', $datetime);
                }
              }
              $ctl_attrs['#forena_date_format'] = @$options['date_parm_format'] ? $options['date_parm_format'] : 'Y-m-d';
              if (@$options['date_year_range']) {
                $ctl_attrs['#date_year_range'] = $options['date_year_range'];
              }
              if (@$options['date_label_position']) {
                $ctl_attrs['#date_label_position'] = $options['date_label_position'];
              }
              $list = array();
              break;
            case 'checkbox':
              if (@$option_str['return_value']) {
                $ctl_attrs['#return_value'] = $options['return_value'];
              }
              $list = array();
              break;
            case 'radios':
              break;
            case 'hidden':
              $list = array();
              break;
            default:
              $type = 'textfield';
              $list = array();
          }
          if (isset($menu_parms[$id]) && $type != 'hidden') {
            $disabled = TRUE;
          }
          //If a data_source attr was found then create an array of
          $form['parms'][$id] = array(
            '#type' => $type,
            '#title' => $label ? $this
              ->t($label) : $this
              ->t($id),
            '#default_value' => $value,
            '#disabled' => $disabled,
            '#required' => $required,
            '#description' => $this
              ->t($desc),
          );
          $form['parms'][$id] = array_merge($form['parms'][$id], $ctl_attrs);
          if ($type == 'item') {
            $form['parms'][$id]['#markup'] = $value;
          }
          if ($type == 'hidden') {
            $form['parms'][$id]['#value'] = $value;
          }
          // Add class to parmeter form.
          if ($class) {
            $form['parms'][$id]['#attributes'] = array(
              'class' => @explode(' ', $class),
            );
          }
          //if $list is not empty then push options
          //onto the array. options will cause an error for
          //textfield elements.
          if ($list || $type == 'select' || $type == 'radios') {
            if ($add_null) {
              $prompt = @$options['prompt'];
              if (!$prompt) {
                $prompt = $required ? '-' . $this
                  ->t('select') . '-' : '-' . t('none') . '-';
              }
              $form['parms'][$id]['#empty_option'] = $prompt;
            }
            $form['parms'][$id]['#options'] = $list;
            $form['parms'][$id]['#multiple'] = $multiselect;
          }
          if ($ajax) {
            $form['parms'][$id]['#ajax'] = array(
              'callback' => 'forena_parameters_callback',
              'wrapper' => 'parameters-wrapper',
            );
          }
        }
        if ($template) {
          $form['parms']['#forena-template'] = $template;
          $form['parms']['#theme'] = 'forena_fieldset_template';
          _forena_set_inline_theme($form['parms']);
        }
        $form['parms']['submit'] = array(
          '#type' => 'submit',
          '#value' => $submit_value,
        );
      }
      //$form_state->setStorage($storage);
      return $form;
    }
    else {
      return NULL;
    }
  }
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    unset($values['parms']['submit']);
    if (isset($values['parms'])) {
      foreach ($values['parms'] as $key => $value) {
        $ctl = $form['parms'][$key];
        switch ($ctl['#type']) {
          case 'date_popup':
          case 'date_select':
          case 'date_text':
            $datetime = @strtotime($value);
            if ($datetime) {
              $value = $values['parms'][$key] = date($ctl['#forena_date_format'], $datetime);
            }
            break;
        }
        if (is_array($value)) {
          $values['parms'][$key] = array();
          foreach ($value as $k => $val) {
            if ($val) {
              $values['parms'][$key][] = $val;
            }
          }
        }
        else {
          if (strpos($value, '|') !== FALSE) {
            $values['parms'][$key] = explode('|', $value);
          }
          elseif ($value === '' || $value === NULL) {
            unset($values['parms'][$key]);
          }
        }
      }
    }
    $path = \Drupal::service('path.current')
      ->getPath();
    $url = Url::fromUserInput($path, [
      'query' => $values['parms'],
    ]);
    $form_state
      ->setRedirectUrl($url);
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of service IDs keyed by property name used for serialization. | |
| 
            DependencySerializationTrait:: | 
                  public | function | 1 | |
| 
            DependencySerializationTrait:: | 
                  public | function | 2 | |
| 
            FormBase:: | 
                  protected | property | The config factory. | 1 | 
| 
            FormBase:: | 
                  protected | property | The request stack. | 1 | 
| 
            FormBase:: | 
                  protected | property | The route match. | |
| 
            FormBase:: | 
                  protected | function | Retrieves a configuration object. | |
| 
            FormBase:: | 
                  protected | function | Gets the config factory for this form. | 1 | 
| 
            FormBase:: | 
                  private | function | Returns the service container. | |
| 
            FormBase:: | 
                  public static | function | 
            Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: | 
                  87 | 
| 
            FormBase:: | 
                  protected | function | Gets the current user. | |
| 
            FormBase:: | 
                  protected | function | Gets the request object. | |
| 
            FormBase:: | 
                  protected | function | Gets the route match. | |
| 
            FormBase:: | 
                  protected | function | Gets the logger for a specific channel. | |
| 
            FormBase:: | 
                  protected | function | 
            Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: | 
                  |
| 
            FormBase:: | 
                  public | function | Resets the configuration factory. | |
| 
            FormBase:: | 
                  public | function | Sets the config factory for this form. | |
| 
            FormBase:: | 
                  public | function | Sets the request stack object to use. | |
| 
            FormBase:: | 
                  public | function | 
            Form validation handler. Overrides FormInterface:: | 
                  62 | 
| 
            FormInterface:: | 
                  public | function | Returns a unique string identifying the form. | 236 | 
| 
            FrxAPI:: | 
                  public | function | Returns containing application service | |
| 
            FrxAPI:: | 
                  public | function | Get the current data context. | |
| 
            FrxAPI:: | 
                  public | function | ||
| 
            FrxAPI:: | 
                  public | function | Returns the data manager service | |
| 
            FrxAPI:: | 
                  public | function | Return Data Service | |
| 
            FrxAPI:: | 
                  public | function | Returns the fornea document manager | |
| 
            FrxAPI:: | 
                  public | function | Report an error | |
| 
            FrxAPI:: | 
                  public | function | Get the context of a specific id. | |
| 
            FrxAPI:: | 
                  public | function | Get the current document | |
| 
            FrxAPI:: | 
                  public | function | Load the contents of a file in the report file system. | |
| 
            FrxAPI:: | 
                  function | Enter description here... | 1 | |
| 
            FrxAPI:: | 
                  public | function | Pop data off of the stack. | |
| 
            FrxAPI:: | 
                  public | function | Push data onto the Stack | |
| 
            FrxAPI:: | 
                  public | function | Run a report with a particular format. | 1 | 
| 
            FrxAPI:: | 
                  public | function | Get the current report file system. | |
| 
            FrxAPI:: | 
                  public | function | Set Data context by id. | |
| 
            FrxAPI:: | 
                  public | function | Change to a specific document type. | |
| 
            FrxAPI:: | 
                  public | function | Get list of skins. | |
| 
            LinkGeneratorTrait:: | 
                  protected | property | The link generator. | 1 | 
| 
            LinkGeneratorTrait:: | 
                  protected | function | Returns the link generator. | |
| 
            LinkGeneratorTrait:: | 
                  protected | function | Renders a link to a route given a route name and its parameters. | |
| 
            LinkGeneratorTrait:: | 
                  public | function | Sets the link generator service. | |
| 
            LoggerChannelTrait:: | 
                  protected | property | The logger channel factory service. | |
| 
            LoggerChannelTrait:: | 
                  protected | function | Gets the logger for a specific channel. | |
| 
            LoggerChannelTrait:: | 
                  public | function | Injects the logger channel factory. | |
| 
            MessengerTrait:: | 
                  protected | property | The messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Gets the messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Sets the messenger. | |
| 
            ParameterForm:: | 
                  public | function | 
            Form constructor. Overrides FormInterface:: | 
                  |
| 
            ParameterForm:: | 
                  public | function | ||
| 
            ParameterForm:: | 
                  public | function | 
            Form submission handler. Overrides FormInterface:: | 
                  |
| 
            RedirectDestinationTrait:: | 
                  protected | property | The redirect destination service. | 1 | 
| 
            RedirectDestinationTrait:: | 
                  protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
| 
            RedirectDestinationTrait:: | 
                  protected | function | Returns the redirect destination service. | |
| 
            RedirectDestinationTrait:: | 
                  public | function | Sets the redirect destination service. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. | |
| 
            UrlGeneratorTrait:: | 
                  protected | property | The url generator. | |
| 
            UrlGeneratorTrait:: | 
                  protected | function | Returns the URL generator service. | |
| 
            UrlGeneratorTrait:: | 
                  public | function | Sets the URL generator service. | |
| 
            UrlGeneratorTrait:: | 
                  protected | function | Generates a URL or path for a specific route based on the given parameters. |