You are here

function gc_gc_process_content_pane in GatherContent 8

Same name and namespace in other branches
  1. 8.3 gathercontent.module \gc_gc_process_content_pane()

Parameters

EntityMetadataWrapper $node: Object of node.

int $gc_id: ID of item in GatherContent.

string $local_field_name: Name of local Drupal field.

object $field: Object of GatherContent field.

string $content_type: Name of Content type, we are mapping to.

bool $is_translatable: Indicator if node is translatable.

string $language: Language of translation if applicable.

1 call to gc_gc_process_content_pane()
_gc_fetcher in ./gathercontent.module
Helper function for fetching data from GatherContent.

File

./gathercontent.module, line 223
Main module file for GatherContent module.

Code

function gc_gc_process_content_pane(EntityMetadataWrapper &$node, $gc_id, $local_field_name, $field, $content_type, $is_translatable = FALSE, $language = \Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED, $plid = NULL, $nid = NULL, &$tsid = NULL, &$_title_is_mapped = FALSE) {
  $field_info = field_info_field($local_field_name);
  $is_translatable = $is_translatable && $field_info['translatable'];
  switch ($field->type) {
    case 'files':
      $content_obj = new Content();
      $files = $content_obj
        ->getFiles($gc_id);
      gc_gc_process_files_field($node, $local_field_name, $field->name, $is_translatable, $language, $files);
      break;
    case 'choice_radio':
      gc_gc_process_choice_radio_field($node, $local_field_name, $field->name, $is_translatable, $language, $field->options);
      break;
    case 'choice_checkbox':
      gc_gc_process_choice_checkbox_field($node, $local_field_name, $field->name, $is_translatable, $language, $field->options);
      break;
    case 'section':
      gc_gc_process_section_field($node, $local_field_name, $field->name, $is_translatable, $language, $field);
      break;
    default:
      if ($local_field_name === 'title') {
        $node->title
          ->set($field->value);
        $_title_is_mapped = TRUE;
        gc_create_menu_link($nid, $field->value, $plid);
      }
      else {
        if ($is_translatable) {
          if (title_field_replacement_enabled('node', $content_type, 'title') && title_field_replacement_info('node', 'title')['field']['field_name'] === $local_field_name) {

            // If we are setting title for default language,
            // we set it just into title attribute and
            // it's synced automatically.
            // @see http://andrejgaluf.com/blog/2015-11-27/drupal-7-setting-title-module-field-programmatically
            if ($language === $node->language
              ->value()) {
              $node->title
                ->set($field->value);
            }
            else {
              $node
                ->language($language)->{$local_field_name}
                ->set($field->value);
            }
            gc_create_menu_link($nid, $field->value, $plid, $language, $tsid);
          }
          else {
            $node
              ->language($language)->{$local_field_name}
              ->set(array(
              'value' => $field->value,
              'format' => $field->plain_text ? 'plain_text' : 'filtered_html',
            ));
          }
        }
        else {
          $node->{$local_field_name}
            ->set(array(
            'value' => $field->value,
            'format' => $field->plain_text ? 'plain_text' : 'filtered_html',
          ));
        }
      }
      break;
  }
}