You are here

public function ViewsJsonQuery::buildOptionsForm in Views Json Source 8

Same name and namespace in other branches
  1. 1.x src/Plugin/views/query/ViewsJsonQuery.php \Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery::buildOptionsForm()

Options form.

Overrides PluginBase::buildOptionsForm

File

src/Plugin/views/query/ViewsJsonQuery.php, line 477

Class

ViewsJsonQuery
Base query handler for views_json_source.

Namespace

Drupal\views_json_source\Plugin\views\query

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  $form['json_file'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('JSON File'),
    '#default_value' => $this->options['json_file'],
    '#description' => $this
      ->t("The URL or relative path to the JSON file(starting with a slash \"/\")."),
    '#maxlength' => 1024,
  ];
  $form['row_apath'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Row Apath'),
    '#default_value' => $this->options['row_apath'],
    '#description' => $this
      ->t("Apath to records.<br />Apath is just a simple array item find method. Ex:<br /><pre>['data' => \n\t['records' => \n\t\t[\n\t\t\t['firstname' => 'abc', 'lastname' => 'pqr'],\n\t\t\t['firstname' => 'xyz', 'lastname' => 'aaa']\n\t\t]\n\t]\n]</pre><br />You want 'records', so Apath could be set to 'data/records'. <br />Notice: Use '%' as wildcard to get the child contents - EG: '%/records', Also add the contextual filter to replace the wildcard('%') with 'data'."),
    '#required' => TRUE,
  ];
  $form['headers'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Headers'),
    '#default_value' => $this->options['headers'],
    '#description' => $this
      ->t("Headers to be passed for the REST call.<br />Pass the headers as JSON string. Ex:<br /><pre>{&quot;Authorization&quot;:&quot;Basic xxxxx&quot;,&quot;Content-Type&quot;:&quot;application/json&quot;}</pre><br />.Here we are passing 2 headers for making the REST API call."),
    '#required' => FALSE,
  ];
  $form['single_payload'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Response contain single node.'),
    '#default_value' => $this->options['single_payload'],
    '#description' => $this
      ->t('Select the checkbox, if the response contains a single item(not a listing API).'),
    '#required' => FALSE,
  ];
  $form['show_errors'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show JSON errors'),
    '#default_value' => $this->options['show_errors'],
    '#description' => $this
      ->t('If there were any errors during JSON parsing, display them. It is recommended to leave this on during development.'),
    '#required' => FALSE,
  ];
}