You are here

public function GatherContentCurl::generateFormSettings in GatherContent 7.2

Generate page settings for pages_import page.

File

includes/curl.inc, line 506
Contains functions used to process and retrieve data from GatherContent.

Class

GatherContentCurl
@file Contains functions used to process and retrieve data from GatherContent.

Code

public function generateFormSettings($form, $array, $index = -1, $show_settings = FALSE) {
  $index++;
  $prefix = '';
  $selected = variable_get('gathercontent_selected_pages');
  if (!$this
    ->foreachSafe($selected)) {
    $selected = array();
  }
  if ($index > 0) {
    for ($i = 0; $i < $index; $i++) {
      $prefix .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    }
    $prefix .= '↳';
  }
  foreach ($array as $id => $page) {
    if ($show_settings && !in_array($id, $selected)) {
      if (isset($page->children) && count($page->children) > 0) {
        $form = $this
          ->generateFormSettings($form, $page->children, $index, $show_settings);
      }
      continue;
    }
    $form['page_list'][$id] = array(
      'page_state' => array(
        '#markup' => '<span data-page-state="' . $page->custom_state_id . '" class="page-status page-state-color-' . $this->data['states'][$page->custom_state_id]->color_id . '"></span>',
      ),
      'page_name' => array(
        '#markup' => $prefix . '<span>' . $page->name . '</span>',
      ),
    );
    $config = $this
      ->getFieldConfig($page);
    $field_count = $this
      ->val($config, 'field_count', 0);
    if ($show_settings && $field_count == 0) {
      $form['pages'][$id] = array(
        '#markup' => '',
      );
    }
    else {
      $form['pages'][$id] = array(
        '#type' => 'checkbox',
        '#return_value' => $id,
        '#default_value' => $show_settings ? $id : 0,
        '#parents' => array(
          'pages',
          $id,
        ),
      );
    }
    if ($show_settings) {
      $cur_settings = array();
      if (isset($this->data['saved_settings'][$id])) {
        $cur_settings = $this->data['saved_settings'][$id];
      }
      if ($field_count > 0) {
        $parent_id = $page->parent_id;
        $this->parentIds[$page->id] = $page->parent_id;
        $parent_id_value = $this
          ->getParentPageId($parent_id, $selected, $cur_settings);
        $form['settings'][$id] = array(
          '#prefix' => '<div>',
          '#suffix' => '</div>',
        );
        $form['settings'][$id]['settings_header'] = array(
          '#prefix' => '<div class="gc_settings_header gc_cf" data-parent-id="' . $parent_id . '">',
          '#suffix' => '</div>',
          'gc_cf' => array(
            '#prefix' => '<div class="gc_cf">',
            '#suffix' => '</div>',
            'import_as' => array(
              '#type' => 'hidden',
              '#prefix' => '<div class="gc_setting gc_import_as" id="gc_import_as_' . $id . '"><label>' . t('Import as ') . '</label>' . $this
                ->dropdownHtml('<span></span>', $this->data['post_types_dropdown']),
              '#suffix' => '</div>',
              '#parents' => array(
                'post_type',
                $id,
              ),
              '#default_value' => $this
                ->val($cur_settings, 'post_type'),
            ),
            'import_to' => array(
              '#type' => 'hidden',
              '#prefix' => '<div class="gc_setting gc_import_to" id="gc_import_to_' . $id . '"><label>' . t('Import to ') . '</label>' . $this
                ->dropdownHtml('<span></span>', $this->data['overwrite_select']),
              '#suffix' => '</div>',
              '#parents' => array(
                'overwrite',
                $id,
              ),
              '#default_value' => $this
                ->val($cur_settings, 'overwrite'),
            ),
            'filter' => array(
              '#type' => 'hidden',
              '#prefix' => '<div class="gc_setting gc_filter" id="gc_filter_' . $id . '"><label>' . t('Text format ') . '</label>' . $this
                ->dropdownHtml('<span></span>', $this->data['formatting']),
              '#suffix' => '</div>',
              '#parents' => array(
                'filter',
                $id,
              ),
              '#default_value' => $this
                ->val($cur_settings, 'filter', $this->defaultFilter),
            ),
            'parent' => array(
              '#type' => 'hidden',
              '#prefix' => '<div class="gc_setting gc_parent" id="gc_parent_' . $id . '"><label>' . t('Parent ') . '</label>' . $this
                ->dropdownHtml('<span></span>', $this->data['parent_select']),
              '#suffix' => '</div>',
              '#parents' => array(
                'parent',
                $id,
              ),
              '#default_value' => $parent_id_value,
            ),
          ),
          'repeat' => array(
            '#markup' => '<div class="gc_setting repeat_config"><label>' . t('Repeat this configuration') . ' <input type="checkbox" id="gc_repeat_' . $id . '" name="gc[repeat_' . $id . ']" value="Y" /></label></div>',
          ),
        );
        $form['settings'][$id]['fields'] = array(
          '#prefix' => '<div class="gc_settings_fields" id="gc_fields_' . $id . '">',
          '#suffix' => '</div>',
        );
        $field_settings = $this
          ->val($cur_settings, 'fields', array());
        if (count($field_settings) > 0) {
          foreach ($field_settings as $name => $value) {
            list($tab, $field_name) = explode('_', $name, 2);
            if (isset($config[$tab]) && isset($config[$tab]['elements'][$field_name])) {
              $tmp = $this
                ->fieldSettings($id, $config[$tab]['elements'][$field_name], $tab, $config[$tab]['label'], $value);
              if ($tmp != '') {
                $form['settings'][$id]['fields'][] = $tmp;
              }
              unset($config[$tab]['elements'][$field_name]);
            }
          }
        }
        unset($config['field_count']);
        foreach ($config as $tab_name => $tab) {
          foreach ($tab['elements'] as $field) {
            $value = $this
              ->val($field_settings, $tab_name . '_' . $field['name']);
            $tmp = $this
              ->fieldSettings($id, $field, $tab_name, $tab['label'], $value);
            if ($tmp != '') {
              $form['settings'][$id]['fields'][] = $tmp;
            }
          }
        }
      }
      else {
        $form['settings'][$id] = array(
          '#markup' => '<div class="alert alert-info">' . sprintf(t('This page is empty. You can %sadd some content to this page in GatherContent%s.'), '<a href="https://' . variable_get('gathercontent_api_url') . '.gathercontent.com/pages/view/' . variable_get('gathercontent_project_id') . '/' . $id . '" target="_blank">', '</a>') . '</div>',
        );
      }
    }
    if (isset($page->children) && count($page->children) > 0) {
      $form = $this
        ->generateFormSettings($form, $page->children, $index, $show_settings);
    }
  }
  return $form;
}