function _filter_fields in GatherContent 8
Same name and namespace in other branches
- 7.3 forms/gathercontent.mapping-edit.inc \_filter_fields()
Helper function.
Use for filtering only equivalent fields.
Parameters
object $gc_field: Type of field in GatherContent.
string $content_type: Name of Drupal content type.
Return value
array Associative array with equivalent fields.
1 call to _filter_fields()
- gc_mapping_edit_form in forms/
gc.mapping-edit.inc - Edit mapping form.
File
- forms/
gc.mapping-edit.inc, line 526 - Multistep mapping form.
Code
function _filter_fields($gc_field, $content_type) {
$mapping_array = array(
'files' => array(
'file',
'image',
),
'section' => array(
'text_long',
),
'text' => array(
'text',
'text_long',
'text_with_summary',
),
'choice_radio' => array(
'text',
),
'choice_checkbox' => array(
'list_text',
),
);
$instances = field_info_instances('node', $content_type);
$fields = array();
// Fields.
foreach ($instances as $name => $instance) {
$field = field_info_field($instance['field_name']);
if (in_array($field['type'], $mapping_array[$gc_field->type])) {
// Constrains:
// - do not map plain text (Drupal) to rich text (GC).
// - do not map radios (GC) to text (Drupal),
// if widget isn't provided by select_or_other module.
// - do not map section (GC) to plain text (Drupal).
switch ($gc_field->type) {
case 'text':
if (!$instance['settings']['text_processing'] && !$gc_field->plain_text || $instance['widget']['module'] === 'select_or_other') {
continue 2;
}
break;
case 'choise_radio':
if ($instance['widget']['module'] !== 'select_or_other') {
continue 2;
}
break;
case 'section':
if (!$instance['settings']['text_processing']) {
continue 2;
}
break;
}
$fields[$instance['field_name']] = $instance['label'];
}
}
if ($gc_field->type === 'text' && $gc_field->plain_text && (!\Drupal::moduleHandler()
->moduleExists('title') || !title_field_replacement_enabled('node', $content_type, 'title'))) {
$fields['title'] = 'Title';
}
return $fields;
}