/**
  * Handle the form.
  *
  * @param PermissionFormBuilder   $builder
  * @param RoleRepositoryInterface $roles
  * @param Redirector              $redirect
  */
 public function handle(PermissionFormBuilder $builder, RoleRepositoryInterface $roles, Redirector $redirect)
 {
     /* @var RoleInterface|EloquentModel $role */
     $role = $builder->getEntry();
     $roles->save($role->setAttribute('permissions', array_filter(array_flatten($builder->getFormInput()))));
     $builder->setFormResponse($redirect->refresh());
 }
 /**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config)
 {
     /* @var RoleInterface $role */
     $role = $builder->getEntry();
     $fields = [];
     $namespaces = ['streams'];
     /* @var Addon $addon */
     foreach ($addons->withConfig('permissions') as $addon) {
         $namespaces[] = $addon->getNamespace();
     }
     foreach ($namespaces as $namespace) {
         foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) {
             $label = $namespace . '::permission.' . $group . '.name';
             if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) {
                 $warning = null;
             }
             if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) {
                 $instructions = null;
             }
             $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => function () use($role, $namespace, $group) {
                 return array_map(function ($permission) use($role, $namespace, $group) {
                     return str_replace($namespace . '::' . $group . '.', '', $permission);
                 }, $role->getPermissions());
             }, 'config' => ['options' => function () use($group, $permissions, $namespace) {
                 return array_combine($permissions, array_map(function ($permission) use($namespace, $group) {
                     return $namespace . '::permission.' . $group . '.option.' . $permission;
                 }, $permissions));
             }]];
         }
     }
     $builder->setFields($fields);
 }
 /**
  * Handle the form.
  *
  * @param PermissionFormBuilder   $builder
  * @param RoleRepositoryInterface $roles
  * @param Redirector              $redirect
  */
 public function handle(PermissionFormBuilder $builder, RoleRepositoryInterface $roles, Redirector $redirect)
 {
     /* @var RoleInterface $role */
     $role = $builder->getEntry();
     $roles->save($role->setPermissions(array_keys(array_dot(array_map(function ($values) {
         return array_combine(array_values($values), array_pad([], count($values), true));
     }, array_filter($builder->getFormInput()))))));
     $builder->setFormResponse($redirect->refresh());
 }
 /**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Repository $config)
 {
     $sections = [];
     $sections['streams']['title'] = 'streams::message.system';
     foreach ($config->get('streams::permissions', []) as $group => $permissions) {
         $sections['streams']['fields'][] = 'streams::' . $group;
     }
     /* @var Addon $addon */
     foreach ($addons->withConfig('permissions') as $addon) {
         $sections[$addon->getNamespace()]['title'] = $addon->getName();
         $sections[$addon->getNamespace()]['description'] = $addon->getDescription();
         foreach ($config->get($addon->getNamespace('permissions'), []) as $group => $permissions) {
             $sections[$addon->getNamespace()]['fields'][] = $addon->getNamespace($group);
         }
     }
     $builder->setSections($sections);
 }
 /**
  * Handle the fields.
  *
  * @param PermissionFormBuilder $builder
  * @param AddonCollection       $addons
  * @param Translator            $translator
  * @param Repository            $config
  */
 public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Translator $translator, Repository $config)
 {
     /* @var RoleInterface $role */
     $role = $builder->getEntry();
     $fields = [];
     $namespaces = array_merge(['streams'], $addons->withConfig('permissions')->namespaces());
     /**
      * gather all the addons with a
      * permissions configuration file.
      *
      * @var Addon $addon
      */
     foreach ($namespaces as $namespace) {
         foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) {
             /**
              * Determine the general
              * form UI components.
              */
             $label = $namespace . '::permission.' . $group . '.name';
             if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) {
                 $warning = null;
             }
             if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) {
                 $instructions = null;
             }
             /**
              * Gather the available
              * permissions for the group.
              */
             $available = array_combine(array_map(function ($permission) use($namespace, $group) {
                 return $namespace . '::' . $group . '.' . $permission;
             }, $permissions), array_map(function ($permission) use($namespace, $group) {
                 return $namespace . '::permission.' . $group . '.option.' . $permission;
             }, $permissions));
             /**
              * Build the checkboxes field
              * type to handle the UI.
              */
             $fields[$namespace . '::' . $group] = ['label' => $label, 'warning' => $warning, 'instructions' => $instructions, 'type' => 'anomaly.field_type.checkboxes', 'value' => $role->getPermissions(), 'config' => ['options' => $available]];
         }
     }
     $builder->setFields($fields);
 }
 /**
  * Return the form for editing permissions.
  *
  * @param PermissionFormBuilder $form
  * @param                       $id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function permissions(PermissionFormBuilder $form, $id)
 {
     return $form->render($id);
 }