मेरे पास नाम क्षेत्र के साथ एक नोड ऑब्जेक्ट है जिसका नाम है field_image। जब मैं करता हूं
$node
->get('field_image')
->first()
->getValue()
मुझे इकाई ऑब्जेक्ट के बजाय कुछ गुणों के साथ सरणी मिलती है। सरणी इस तरह दिखती है:
'target_id' => string '8' (length=1)
'alt' => string '' (length=0)
'title' => string '' (length=0)
'width' => string '587' (length=3)
'height' => string '458' (length=3)
'_loaded' => boolean true
'_accessCacheability' =>
object(Drupal\Core\Cache\CacheableMetadata)[1092]
protected 'cacheContexts' =>
array (size=0)
...
protected 'cacheTags' =>
array (size=0)
...
protected 'cacheMaxAge' => int -1
क्या मुझे फ़ाइल इकाई का उपयोग करना है target_idया उदाहरण के लिए स्वचालित रूप से संदर्भित इकाई वस्तु प्राप्त करने का एक तरीका है Drupal\image\Plugin\Field\FieldType\ImageItem?
क्यों संदर्भित इकाई गटर के माध्यम से सुलभ नहीं है? यदि यह तुरंत उपलब्ध नहीं है तो यह आलसी हो सकता है।
PHP Fatal error: Call to undefined method Drupal\image\Plugin\Field\FieldType\ImageItem::getTarget():। हालाँकि, $node->get('imagefield')->referencedEntities()इस तथ्य के $node->get('imagefield')उदाहरण के लिए काम करता है कि EntityReferenceFieldItemListकिस referencedEntities()विधि का उदाहरण है । तो आपका समाधान केवल आंशिक है - यह सूचियों के लिए काम करता है लेकिन एकल क्षेत्रों के लिए नहीं।