function gc_gc_process_default_field in GatherContent 8.3
Default processing function, when no other matches found, usually for text.
Parameters
\Drupal\node\NodeInterface $entity: Object of node.
string $local_field_name: Local field name.
bool $is_translatable: Indicator if node is translatable.
string $language: Language of translation if applicable.
object $field: Object with field attributes.
1 call to gc_gc_process_default_field()
- gc_gc_process_content_pane in ./
gathercontent.module - Processing function for content panes.
File
- ./
gathercontent.module, line 499 - Main module file for GatherContent module.
Code
function gc_gc_process_default_field(NodeInterface &$entity, $local_field_name, $is_translatable, $language, $field) {
$value = $field->value;
$target =& $entity;
if ($is_translatable) {
$target = $entity
->getTranslation($language);
}
// Title is not a field, breaks everything. Short-circuit here.
if ($local_field_name === 'title') {
$target
->setTitle($value);
return;
}
// For all non-title fields, decide what to do based on Drupal field type.
$field_info = FieldConfig::loadByName('node', $entity
->bundle(), $local_field_name);
switch ($field_info
->getType()) {
case 'datetime':
$value = strtotime($value);
if ($value === FALSE) {
// If we failed to convert to a timestamp, abort.
return;
}
$target->{$local_field_name} = [
'value' => gmdate(DATETIME_DATETIME_STORAGE_FORMAT, $value),
];
break;
case 'date':
$value = strtotime($value);
if ($value === FALSE) {
return;
}
$target->{$local_field_name} = [
'value' => gmdate(DATETIME_DATE_STORAGE_FORMAT, $value),
];
break;
default:
// Probably some kind of text field.
$target->{$local_field_name} = [
'value' => $value,
'format' => $field->plain_text ? 'plain_text' : 'basic_html',
];
break;
}
}