You are here

protected function DynamicFilterForm::generateFunctionItem in Feed Import 8

Generates function fields.

1 call to DynamicFilterForm::generateFunctionItem()
DynamicFilterForm::buildForm in src/Form/DynamicFilterForm.php
Form constructor.

File

src/Form/DynamicFilterForm.php, line 198
Contains \Drupal\feed_import\Form\DynamicFilterForm

Class

DynamicFilterForm

Namespace

Drupal\feed_import\Form

Code

protected function generateFunctionItem($pos, array $values, $collapsed = FALSE) {
  if (!preg_match('/^_[a-z0-9_]+$/i', $values['name'])) {
    return array();
  }
  $container = 'container_' . $pos;
  $item[$container] = array(
    '#type' => 'fieldset',
    '#title' => t('Function @name', array(
      '@name' => $values['name'],
    )),
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
    '#attributes' => array(
      'id' => 'item_container_' . $pos,
    ),
  );
  $container =& $item[$container];
  $container['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('Name must start with underscore and can contain only alphanumeric chars or underscores.'),
    '#default_value' => $values['name'],
    '#attributes' => array(
      'id' => 'func_name_' . $pos,
    ),
  );
  $container['args'] = array(
    '#type' => 'textfield',
    '#title' => t('Parameters'),
    '#description' => t('Use variable names separated by comma, like: $a, $b'),
    '#default_value' => $values['args'],
  );
  $container['body'] = array(
    '#type' => 'textarea',
    '#rows' => 5,
    '#title' => t('Body'),
    '#description' => t('Write only the function body. Do not forget to return a value.'),
    '#default_value' => $values['body'],
  );
  $container['remove_container_' . $pos] = array(
    '#type' => 'button',
    '#name' => 'remove_container_' . $pos,
    '#value' => t('Remove function'),
    '#ajax' => array(
      'event' => 'click',
      'wrapper' => 'item_container_' . $pos,
      'callback' => array(
        $this,
        'ajaxRemoveItem',
      ),
      'method' => 'replaceWith',
    ),
  );
  return $item;
}