setRole example

$resource = new $class();
        }

        $resource->setManager($this->getManager());

        if ($this->getAcl() !== null) {
            $resource->setAcl($this->getAcl());
        }

        if ($this->getRole() !== null) {
            $resource->setRole($this->getRole());
        }

        return $resource;
    }

    /** * Helper function which checks the option configuration for the passed collection. * * If the data property contains the "__options_$optionName" value and this value contains * the "replace" parameter, the collection will be cleared. * * @template TEntity of ModelEntity * * @param ArrayCollection<array-key, TEntity> $collection * @param array<array-key, array<string, mixed>> $data * @param string $optionName * @param bool $defaultReplace * * @return ArrayCollection<array-key, TEntity> */
'message' => $namespace->get('no_role_passed', 'No valid role id passed'),
            ]);

            return;
        }
        // Get new role rules         $newRules = $this->Request()->getParam('privileges', null);

        // Iterate the new rules and create shopware models         foreach ($newRules as $newRule) {
            $rule = new Rule();
            $rule->setRole($role);

            if (isset($newRule['resourceId'])) {
                $resource = $this->get('models')->find(Resource::class$newRule['resourceId']);
                $rule->setResource($resource);
            }
            if (isset($newRule['privilegeId'])) {
                /** @var Privilege $privilege */
                $privilege = $this->get('models')->find(Privilege::class$newRule['privilegeId']);
                $rule->setPrivilege($privilege);
            } else {
                $rule->setPrivilege(null);
            }
$em = $this->container->get(ModelManager::class);
        $em->persist($user);
        $em->flush($user);
    }

    private function createAdminUser(): User
    {
        $adminRole = $this->getAdminRole();

        $user = new User();
        $user->setRoleId($adminRole->getId());
        $user->setRole($adminRole);

        return $user;
    }

    private function validateInput(InputInterface $input): void
    {
        $option = $input->getOption('email');
        if (empty($option)) {
            throw new InvalidArgumentException('Email is required');
        }

        
$class = __NAMESPACE__ . '\\Resource\\' . $name;

            /** @var Resource\Resource $resource */
            $resource = new $class();

            $resource->setContainer($container);
            $resource->setManager($container->get(\Shopware\Components\Model\ModelManager::class));
        }

        if ($container->initialized('auth')) {
            $resource->setAcl($container->get('acl'));
            $resource->setRole($container->get('auth')->getIdentity()->role);
        }

        return $resource;
    }
}
protected $apiBaseUrl;

    /** * @var AbstractResource */
    protected $resource;

    public function preDispatch()
    {
        if (($this->resource instanceof AbstractResource) && $this->container->initialized('auth')) {
            $this->resource->setAcl($this->container->get('acl'));
            $this->resource->setRole($this->container->get('auth')->getIdentity()->role);
        }

        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $this->apiBaseUrl = $this->Request()->getScheme()
           . '://'
           . $this->Request()->getHttpHost()
           . $this->Request()->getBaseUrl()
           . '/api/';
    }

    
Home | Imprint | This part of the site doesn't use cookies.