protected function SocialContent::attachFields in Social Content 7.2
Attach declare fields onto wrapper.
Parameters
array $fields: The fields to attach the wrapper to.
EntityMetadataWrapper $wrapper: The wrapper to which to attach the wrappers to
object $row: The row to which to map the fields from.
1 call to SocialContent::attachFields()
- SocialContent::import in ./
social_content.class.inc - Do the import.
File
- ./
social_content.class.inc, line 659 - Social Content class.
Class
- SocialContent
- TODO: Table names should be a property for ease of change Separate this class into smaller classes.
Code
protected function attachFields($fields, $wrapper, $row) {
$fields = array_filter($fields);
$property_info = $wrapper
->getPropertyInfo();
foreach ($fields as $key => $field_name) {
if (strpos($key, '.') === 0) {
$value = self::getDynamicProperty($row, explode('.', $key));
}
elseif (isset($row->{$key})) {
$value = $row->{$key};
}
else {
continue;
}
if (isset($property_info[$field_name])) {
if (isset($property_info[$field_name]['property info']['file']) && is_string($value)) {
$file = $this
->saveExternalFile($value, $field_name);
$value = !empty($file) ? $file : NULL;
}
elseif ($property_info[$field_name]['type'] == 'text') {
$value = self::validateText($value);
}
elseif (in_array($property_info[$field_name]['type'], array(
'text_formatted',
'field_item_textsummary',
))) {
$value = self::validateText($value);
$value = is_array($value) ? $value : array(
'value' => $value,
'format' => 'filtered_html',
);
}
elseif ($property_info[$field_name]['type'] == 'field_item_link') {
$value = array(
'url' => $value,
);
}
elseif (in_array($property_info[$field_name]['type'], array(
'list<taxonomy_term>',
'taxonomy_term',
))) {
$terms = array();
$vid = taxonomy_vocabulary_machine_name_load($property_info[$field_name]['bundle'])->vid;
if ($value && !is_array($value)) {
$value = array(
$value,
);
}
foreach ($value as $name) {
$name = self::validateText($name);
$term = taxonomy_get_term_by_name($name, $property_info[$field_name]['bundle']);
if (!$term) {
$term = new stdClass();
$term->name = $name;
$term->vid = $vid;
taxonomy_term_save($term);
$term = taxonomy_get_term_by_name($name, $property_info[$field_name]['bundle']);
}
$terms[] = array_pop($term)->tid;
}
$value = $terms;
}
if ($value) {
$wrapper->{$field_name}
->set($value);
}
}
}
}