Get display name (select)


#1

Hi,

I’d like to get the display name of a select field.
How is this possible?

Cheers,


#2

Hi there,

assuming you mean the display names of class selects, here is your solution:

$o = DataObject::getById(49);
$values = DataObject\Service::getOptionsForMultiSelectField($o, "multiselect"); // for a multiselect data field
$values1 = DataObject\Service::getOptionsForSelectField($o, "select"); // for a select data field

You can find this passage here in the documentation (for version 5): https://pimcore.com/docs/5.0.x/Development_Documentation/Objects/Object_Classes/Data_Types/Select_Types.html

Cheers,
Daniel


#3

Hi,

yeah I found that part of the documentation.
But I assumed that you get ALL options for a select field, but I want to get only the selected option

Cheers


#4

Good morning,

this is also no problem – just go like this:

$o = DataObject::getById(49);
$values = DataObject\Service::getOptionsForSelectField($o, 'select');
$selectedValue = $values[$o->getSelect()];

Cheers,
Daniel


#5

Ha yeah!

Thanks!

Cheers


#6

This not working when select it’s in a block data type.

https://pimcore.com/docs/5.x/Development_Documentation/Objects/Object_Classes/Data_Types/Blocks.html

Does anyone know how to do it? Thanks.