Can't get User Attribute Select Options

Permalink
This code in 8.2.1 no longer works

$cak = \UserAttributeKey::getByHandle('area_interest');
$at = \Concrete\Core\Attribute\Type::getByHandle('select');
$satc = new \Concrete\Attribute\Select\Controller($at);
 $satc->setAttributeKey($cak);
 $values = $satc->getOptions();
 if (!empty($values)) {
    foreach($values as $value) {
           echo sprintf("<option value=\"%s\">%s</option>", $value, $value);
    }
}


Anyone have the new code for getting a select attributes' options?

This line:
$satc = new \Concrete\Attribute\Select\Controller($at);


Apparently $at isn't the right type.

Throws this error -
Argument 1 passed to Concrete\Core\Attribute\Controller::__construct() must be an instance of Doctrine\ORM\EntityManager, instance of DoctrineProxies\__CG__\Concrete\Core\Entity\Attribute\Type given, called in /var/www/public/nanostring2017.local/application/themes/nanostring/elements/footer.php on line 63 and defined

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi justinba,

You can try this:
$cak = \UserAttributeKey::getByHandle('area_interest');
$em = \Database::connection()->getEntityManager();
$satc = new \Concrete\Attribute\Select\Controller($em);
$satc->setAttributeKey($cak);
$values = $satc->getOptions();
if ($values) {
    foreach ($values as $value) {
        echo sprintf("<option value=\"%s\">%s</option>", $value, $value);
    }
}
justinba replied on at Permalink Best Answer Reply
Thanks, MrK!

I actually wound up doing a bit of digging into some of the Express core stuff and came up with this.

$cak = \UserAttributeKey::getByHandle('area_interest');
$options = $cak->getController()->getOptions();
if (!empty($options)) {
    foreach($options as $option) {
         echo sprintf("<option value=\"%s\">%s</option>", $option->getSelectAttributeOptionDisplayValue(), $option->getSelectAttributeOptionDisplayValue());
    }
}


Hope this thread helps someone else! Thanks for the reply!