Creating file attribute set and adding file attributes to it...

Permalink
Hi i've been going in circle with this, can anyone please help?

The error i'm getting is:

Using $this when not in object context, in SetFactory.php
public function getByHandle($atHandle)
    {
        $r = $this->entityManager->getRepository('\Concrete\Core\Entity\Attribute\Set');
        return $r->findOneBy(array('asHandle' => $atHandle));
    }


Thanks in advance:

public static function installFileAttributes($pkg)
    {
            $set = SetFactory::getByHandle('drivecast');
            if (!is_object($set)) {
               $categoryEntity = CategoryService::getByHandle('file');
               $category = $categoryEntity->getController();
               $setManager = $category->getSetManager();
               $set = $setManager->addSet('drivecast', 'Drivecast', $pkg);
            }
        self::installFileAttribute('select', 'author', 'Author', $set, $pkg);
        self::installFileAttribute('select', 'series', 'Series', $set, $pkg);
    }
    public static function installFileAttribute($type, $handle, $name, $set, $pkg)
    {
         $key = $category->getByHandle($handle);

BHWW
View Replies:
hutman replied on at Permalink Reply
hutman
This doesn't answer your question, but is there any reason you're not creating attributes with an install.xml file? They are really easy for v8+
BHWW replied on at Permalink Reply
BHWW
Hi Hutman (again)

The only reason being that despite developing in Concrete5 for over a decade, I am completely oblivious to your suggestion. Any documentation?

Thanks again
mnakalay replied on at Permalink Reply
mnakalay
Concerning the $this issue.
You are calling
$set = SetFactory::getByHandle('drivecast');

What that means is you are calling that function from SetFactory statically so without creating a SetFactory object. In SetFactory, $this refers to the current object but since there are none it throws an error.
If you had done
$setFactory = new SetFactory();
$set = $setFactory->getByHandle('drivecast');

There would have been an object and $this would refer to it.

As for using nstall.xml the info you need is here:https://documentation.concrete5.org/developers/packages/concrete5-ci...
at the bottom, there is a link to an attribute creation example.
hutman replied on at Permalink Reply
hutman
Here is an example of how I have created a select attribute with the XML file, the documentation is lacking in this, but if you look at the files in /concrete/config/install/base/ there are a lot of examples there.

<?xml version="1.0"?>
<concrete5-cif version="1.0">
    <attributekeys>
        <attributekey
            handle="attribute_handle"
            name="Attribute Name"
            package="package_name"
            searchable="1"
            indexed="1"
            type="select"
            category="file"
            >
            <type
                allow-multiple-values="0"
                display-order="display_asc"