Retrieving a list of all page attributes

Permalink
I want to have a list of the attributes that are currently setup in the system, so that I can choose the attribute handle of one of them. I dont want the available choices in a particular attribute.

I have a block, and in my block I have to specify an attribute handle of a (select)attribute I want to choose/use in the block editing. I currently just have a text field, which I fill in the attribute handle, and that works fine. To make it more user friendly, I want to make a dropdown, populated with attribute handles I can choose from.

How would I go about doing something like this??
$aks = CollectionAttribute::getAllAttributes();
echo '<select>';
foreach( $aks AS $key ){
  echo "<option value=\"{$key->handle}\">{$key->name}</option>";
}
echo '</select>';


Any help would be much appreciated! Thanks, Andrew

adavis
View Replies:
adavis replied on at Permalink Reply
adavis
This actually works, to return a list of ALL attributes available.
$keyslist = AttributeKey::getList('Collection');
foreach($keyslist AS $key){
   echo "<p>{$key->akHandle}</p>";
}


I see that If I print_r the actual attribute objects, there is a pkgId value. If I could know what that pkgId is I could do something like this, which would return the attributes created in the package (more ideal situation!)

$pkg= Package::getById($the_id);
$keylist = AttributeKey::getListByPackage($pkg);


I dont see how I can know, from within the block controller, what package that block belongs to??
adavis replied on at Permalink Reply
adavis
I also dont see how I can know, from within the block controller, what block id it is.... Im so confused today =/
adavis replied on at Permalink Reply
adavis
I've settled on this for now. It does not give me kackage or block secific attributes, but in my application it could be possible to use ANY Select attribute to populate my block.

CONTROLLER in the edit() method:
Loader::model('attribute/key')
$keyslist = AttributeKey::getList('Collection');
$available_aks=array(''=>'(none)');
foreach($keyslist AS $key){
   if( $key->getAttributeType()->getAttributeTypeName() == 'Select' ){
      $available_aks["{$key->akHandle}"] = $key->akName;
   }
}
$this->set('available_aks', $available_aks );


In the edit/add files:
<?php echo $form->label('category1AttributeHandle', 'Category 1 attribute handle');?>
<?php echo $form->select('category1AttributeHandle', $available_aks, $category1AttributeHandle );?>
<br/>(Handle of the attribute that will populate selector.)
Mireck78 replied on at Permalink Reply
Mireck78
//This is not working (C5 v5.6) - 'Collection' needs to be in lower case letters 
AttributeKey::getList('Collection');
//This works
AttributeKey::getList('collection');
RadiantWeb replied on at Permalink Reply
RadiantWeb
Try this:

global $c;
$atts = $c->getSetCollectionAttributes();
//var_dump($atts);
foreach($atts as $at){
   echo $at->akHandle .' - '. $at->akID;
   echo '<br/>';
}


ChadStrat
lucasschirm replied on at Permalink Reply
The easy way in the new version is just:

$attList = \Concrete\Core\Attribute\Key\CollectionKey::getList();
//you can
var_dump($attList);