grav-plugin-flex-objects
grav-plugin-flex-objects copied to clipboard
Flex Users storage problem
I want to store users in accounts\username folder.
In my config\system.yaml:
accounts:
type: flex
storage: folder
avatar: gravatar
I copied system/blueprints/flex/user-accounts.yaml to user/blueprints/flex/user-accounts.yaml. Data configuration part:
# Data Configuration
data:
object: 'Grav\Common\Flex\Types\Users\UserObject'
collection: 'Grav\Common\Flex\Types\Users\UserCollection'
index: 'Grav\Common\Flex\Types\Users\UserIndex'
storage:
class: 'Grav\Common\Flex\Types\Users\Storage\UserFolderStorage'
options:
formatter:
class: 'Grav\Framework\File\Formatter\YamlFormatter'
folder: 'account://'
pattern: '{FOLDER}/{KEY}{EXT}'
indexed: true
key: username
case_sensitive: false
All should be fine but users are saved to hashed folders:

As you can see with Xdebug, pattern and storage_key are wrong (not from our storage configuration):

Ok. I can extend UserObject to my custom to override save() func:
<?php
declare(strict_types=1);
namespace Grav\Plugin\SoglFlex\Flex\Types\Users;
use Grav\Common\Grav;
use Grav\Common\Flex\Types\Users\UserObject as DefaultUserObject;
class UserObject extends DefaultUserObject
{
/**
* {@inheritdoc}
* @see FlexObjectInterface::save()
*/
public function save()
{
if (!$this->exists()) {
$this->setStorageKey($this->getProperty('username'));
}
parent::save();
}
}
Much better but still triple nesting:

BUT when I try to override class: 'Grav\Plugin\SoglFlex\Flex\Types\Users\UserFolderStorage' it just not fire.
It looks as if the entire storage section is not being read, but the default values are being used.
@mahagr How to fix?
After hours of debugging I found that if I write in config\system.yaml:
accounts:
type: flex
storage: SOMETHING
avatar: gravatar
My custom class works fine and also all other storage options from user-accounts.yaml.
However, each time of Configuration saving (in Admin panel) storage: SOMETHING will be overwritten. Need to add +1 value for custom or something else:
