Something went wrong. Try again.
Element Exporter makes exporting data from your Craft CMS website easy and repeatable, with events for custom data parsing and elements.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061<?php
namespace studioespresso\exporter\fields;
use Craft;use craft\base\Element;
class RelationFieldParser extends BaseFieldParser{ public function getValue(Element $element, array $field) { /** @var Element|null $element */
$relations = $element->getFieldValue($field['handle'])->all(); $property = $field['property'];
$result = []; foreach ($relations as $relation) { if (isset($relation->$property)) { $result[] = $relation->$property; } else { $result[] = $relation->id; } }
if (empty($result)) { return ''; }
if (count($result) === 1) { return $result[0]; }
return implode(',', $result); }
public function getOptions(): array { return [ 'title' => Craft::t('app', 'Title'), 'id' => Craft::t('app', 'ID'), 'url' => Craft::t('app', 'URL'), ]; }
public function getOptionType(): string { return "select"; }
public function getOptionLabel(): string|bool { return Craft::t('exporter', 'Select element property'); }
public function getOptionDescription(): string|bool { return Craft::t('exporter', 'Select which property on the selected element you want to include in the export.'); }}