SelectAttributeTypeOption not recognized by C5

Permalink
Hello All
I'm trying to create an advanced autonav block package & written this code into package controller. Concrete5 doesn't recognize "SelectAttributeTypeOption". Any idea why? Am I doing anything wrong?

use Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption as SelectAttributeTypeOption;
$attr = CollectionAttributeKey::getByHandle('stack_row'); 
      if( !is_object($attr) ) {
         CollectionAttributeKey::add($select_att,array(
         'akHandle' => 'stack_row',
         'akIsSearchable' => true, 
         'akIsSearchableIndexed' => true,
         'akSelectAllowMultipleValues' => false,
         'akSelectAllowOtherValues' => false,
         'akSelectOptionDisplayOrder' => 'alpha_asc',
         'akName' => t('Add sublevel row with grid')),
         $pkg)->setAttributeSet($att_set);  
         $attr=CollectionAttributeKey::getByHandle('stack_row');      
         SelectAttributeTypeOption::add( $attr, 'Option 1');
         SelectAttributeTypeOption::add( $attr, 'Option 1');


Thanks

ronyDdeveloper
 
mnakalay replied on at Permalink Reply
mnakalay
in v8 Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption doesn't have an add() function

What version are you using?
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
Hi mnakalay
I'm using version 8.4.0, I know I'm doing something wrong. But cannot find the right solution.

Rony
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
Any thoughts on this. I'm really in a need to fix this.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
This works for me
<?php
$service = $this->app->make('Concrete\Core\Attribute\Category\CategoryService');
$category = $service->getByHandle('collection');
$key = $category->getByHandle('stack_row');
if (!is_object($key)) {
    $pkg = Package::getByHandle('your_package_handle');
    $selectAttributeType = \Concrete\Core\Attribute\Type::getByHandle('select');
    //the options you want to add to your select attribute
    $optionsList = ['option 1', 'option 2'];
    $selectSettings = new \Concrete\Core\Entity\Attribute\Key\Settings\SelectSettings();
    $list = new \Concrete\Core\Entity\Attribute\Value\Value\SelectValueOptionList();
    $options = [];
    $displayOrder = 0;
    foreach ($optionsList as $option) {
        $opt = new \Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption();
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
Hi mnakalay
Thank you very much for the code. It works for me. If you know how to add them to a set, please share with me.

Thanks
mnakalay replied on at Permalink Reply
mnakalay
linuxoid replied on at Permalink Reply
linuxoid
I'm trying this:
// Install category 'Car'
$akc = AttributeCategory::add('car', AttributeCategory::ASET_ALLOW_SINGLE, $pkg);
$service = $this->app->make('Concrete\Core\Attribute\Category\CategoryService');
$category = $service->getByHandle('car');
$key = $category->getByHandle('gear_box'); // <- Exception

where it throws an exception "Call to undefined method Concrete\Core\Entity\Attribute\Category::getByHandle()"