public function Entity::processField in Convert Media Tags to Markup 8
Same name and namespace in other branches
- 2.x src/ConvertMediaTagsToMarkup/Entity.php \Drupal\convert_media_tags_to_markup\ConvertMediaTagsToMarkup\Entity::processField()
Process a field.
Parameters
string $fieldname: A field name.
object $field: A field list object.
bool $simulate: Whether or not to Simulate the results.
string $log: For example "print_r" or "dpm".
Throws
Exception
1 call to Entity::processField()
- Entity::process in src/
ConvertMediaTagsToMarkup/ Entity.php - Process this entity; change the media tags code to an image tag.
File
- src/
ConvertMediaTagsToMarkup/ Entity.php, line 62
Class
- Entity
- Represents a Drupal entity for our purposes.
Namespace
Drupal\convert_media_tags_to_markup\ConvertMediaTagsToMarkupCode
public function processField(string $fieldname, $field, bool $simulate = TRUE, $log = 'print_r') {
$log('Processing field ' . $fieldname . ' of class ' . get_class($field) . ' for entity ' . $this->entity
->id() . PHP_EOL);
$value = $field
->getValue();
foreach ($value as $delta => $row) {
if (!empty($row['value']) && !empty($row['format'])) {
$log(' => Item at position ' . $delta . ' is a candidate for processing' . PHP_EOL);
$value[$delta]['value'] = App::instance()
->filterText($row['value']);
if ($simulate) {
$log('Simulating changing the content to: ' . PHP_EOL);
$log($value[$delta]['value']);
$log(PHP_EOL);
}
else {
$this->entity->{$fieldname} = $value;
$log('Changed its content.' . PHP_EOL);
}
}
else {
$log(' => Item at position ' . $delta . ' is not a candidate for processing' . PHP_EOL);
}
}
}