/**
  * Create a new field assignment.
  *
  * @param AssignmentFormBuilder     $builder
  * @param DiskRepositoryInterface   $disks
  * @param FieldRepositoryInterface  $fields
  * @param StreamRepositoryInterface $streams
  * @param                           $id
  * @param                           $field
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(AssignmentFormBuilder $builder, DiskRepositoryInterface $disks, FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, $id, $field)
 {
     /* @var DiskInterface $disk */
     $disk = $disks->find($id);
     $stream = $streams->findBySlugAndNamespace($disk->getSlug(), 'files');
     return $builder->setOption('redirect', 'admin/files/disks/assignments/' . $id)->setField($fields->find($field))->setStream($stream)->render();
 }
 /**
  * Reset the migration.
  *
  * @param Migration $migration
  */
 public function reset(Migration $migration)
 {
     $this->input->read($migration);
     foreach ($migration->getFields() as $field) {
         if ($field = $this->fields->findBySlugAndNamespace($field['slug'], $field['namespace'])) {
             $this->fields->delete($field);
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @param FieldRepositoryInterface      $fields
  * @param StreamRepositoryInterface     $streams
  * @param AssignmentRepositoryInterface $assignments
  */
 public function fire(FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, AssignmentRepositoryInterface $assignments)
 {
     $streams->cleanup();
     $this->info('Abandoned streams deleted successfully.');
     $fields->cleanup();
     $this->info('Abandoned fields deleted successfully.');
     $assignments->cleanup();
     $this->info('Abandoned assignments deleted successfully.');
 }
 /**
  * Run the seeder.
  */
 public function run()
 {
     if ($type = $this->types->findBySlug('default_posts')) {
         $this->types->delete($type);
     }
     /* @var TypeInterface $type */
     $type = $this->types->truncate()->create(['en' => ['name' => 'Default', 'description' => 'A simple post type.'], 'slug' => 'default', 'theme_layout' => 'theme::layouts/default.twig', 'layout' => '{{ post.content|raw }}']);
     $stream = $type->getEntryStream();
     $this->assignments->create(['stream' => $stream, 'field' => $this->fields->findBySlugAndNamespace('content', 'posts')]);
 }
    /**
     * Run the seeder.
     */
    public function run()
    {
        if ($type = $this->types->findBySlug('default_pages')) {
            $this->types->delete($type);
        }
        /* @var TypeInterface $type */
        $type = $this->types->truncate()->create(['en' => ['name' => 'Default', 'description' => 'A simple page type.'], 'slug' => 'default', 'handler' => 'anomaly.extension.default_page_handler', 'theme_layout' => 'theme::layouts/default.twig', 'layout' => '<h1>{{ page.title }}</h1>

{{ page.content|raw }}']);
        $stream = $type->getEntryStream();
        $this->assignments->create(['stream' => $stream, 'field' => $this->fields->findBySlugAndNamespace('content', 'pages')]);
    }
 /**
  * Handle the command.
  *
  * @param RollbackFields $command
  */
 public function handle(RollbackFields $command)
 {
     $migration = $command->getMigration();
     $addon = $migration->getAddon();
     $namespace = $migration->getNamespace();
     foreach ($migration->getFields() as $slug => $field) {
         $namespace = array_get($field, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null));
         if ($field = $this->fields->findBySlugAndNamespace($slug, $namespace)) {
             $this->fields->delete($field);
         }
     }
 }
 /**
  * Reset the migration.
  *
  * @param Migration $migration
  */
 public function reset(Migration $migration)
 {
     $this->input->read($migration);
     if (!($stream = $migration->getStream())) {
         return;
     }
     $assignments = $migration->getAssignments();
     $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace'));
     if (!$stream) {
         return;
     }
     foreach ($assignments as $assignment) {
         /*
          * If there is no field to be
          * found then the assignment
          * needs to be cleaned out.
          *
          * @var FieldInterface
          */
         if (!($field = $this->fields->findBySlugAndNamespace($assignment['field'], $stream->getNamespace()))) {
             continue;
         }
         $assignment['field'] = $field;
         $assignment['stream'] = $stream;
         /*
          * Check if the field is already
          * assigned to the stream and
          * then go ahead and delete.
          */
         if ($assignment = $this->assignments->findByStreamAndField($stream, $field)) {
             $this->assignments->delete($assignment);
         }
     }
 }
 /**
  * Handle the command.
  *
  * @param FieldRepositoryInterface      $fields
  * @param StreamRepositoryInterface     $streams
  * @param AssignmentRepositoryInterface $assignments
  */
 public function handle(FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, AssignmentRepositoryInterface $assignments)
 {
     $addon = $this->migration->getAddon();
     $stream = $this->migration->getStream();
     $namespace = array_get($stream, 'namespace', $this->migration->getNamespace());
     $slug = array_get($stream, 'slug', $addon ? $addon->getSlug() : null);
     $stream = $streams->findBySlugAndNamespace($slug, $namespace);
     foreach ($this->migration->getAssignments() as $field => $assignment) {
         if (is_numeric($field)) {
             $field = $assignment;
         }
         if ($stream && ($field = $fields->findBySlugAndNamespace($field, $namespace))) {
             if ($assignment = $assignments->findByStreamAndField($stream, $field)) {
                 $assignments->delete($assignment);
             }
         }
     }
     $assignments->cleanup();
 }
 /**
  * Create a new assignment.
  *
  * @param AssignmentFormBuilder    $builder
  * @param TypeRepositoryInterface  $types
  * @param FieldRepositoryInterface $fields
  * @param                          $type
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(AssignmentFormBuilder $builder, TypeRepositoryInterface $types, FieldRepositoryInterface $fields, $type)
 {
     /* @var TypeInterface $type */
     $type = $types->find($type);
     return $builder->setField($fields->find($this->request->get('field')))->setStream($type->getEntryStream())->render();
 }
 /**
  * Handle the command.
  *
  * @param MigrateFields $command
  * @return bool
  */
 public function handle(MigrateFields $command)
 {
     $migration = $command->getMigration();
     /* @var Addon $addon */
     $addon = $migration->getAddon();
     $fields = $migration->getFields();
     $namespace = $migration->getNamespace();
     foreach ($fields as $slug => $field) {
         if (is_string($field)) {
             $field = ['type' => $field];
         }
         $field['slug'] = $slug;
         $field['type'] = array_get($field, 'type');
         $field['namespace'] = array_get($field, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null));
         /**
          * If the name exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($name = array_pull($field, 'name')) {
             $field = array_add($field, config('app.fallback_locale') . '.name', $name);
         }
         /**
          * If the name is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($field, config('app.fallback_locale') . '.name')) {
             $field = array_add($field, config('app.fallback_locale') . '.name', $addon ? $addon->getNamespace("field.{$slug}.name") : null);
         }
         /**
          * If the instructions exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($instructions = array_pull($field, 'instructions')) {
             $field = array_add($field, config('app.fallback_locale') . '.instructions', $instructions);
         }
         /**
          * If the instructions is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($field, config('app.fallback_locale') . '.instructions')) {
             $field = array_add($field, config('app.fallback_locale') . '.instructions', $addon ? $addon->getNamespace("field.{$slug}.instructions") : null);
         }
         /**
          * If the placeholder exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($placeholder = array_pull($field, 'placeholder')) {
             $field = array_add($field, config('app.fallback_locale') . '.placeholder', $placeholder);
         }
         /**
          * If the placeholder is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($field, config('app.fallback_locale') . '.placeholder')) {
             $field = array_add($field, config('app.fallback_locale') . '.placeholder', $addon ? $addon->getNamespace("field.{$slug}.placeholder") : null);
         }
         /**
          * If the warning exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($warning = array_pull($field, 'warning')) {
             $field = array_add($field, config('app.fallback_locale') . '.warning', $warning);
         }
         /**
          * If the instructions is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($field, config('app.fallback_locale') . '.warning')) {
             $field = array_add($field, config('app.fallback_locale') . '.warning', $addon ? $addon->getNamespace("field.{$slug}.warning") : null);
         }
         // Only create if it does not exist already.
         if (!($entry = $this->fields->findBySlugAndNamespace($field['slug'], $field['namespace']))) {
             $this->fields->create($field);
         } else {
             $this->fields->save($entry->fill($field));
         }
     }
     return true;
 }
 /**
  * Assign a field to a post type.
  *
  * @param AssignmentFormBuilder     $form
  * @param TypeRepositoryInterface   $types
  * @param FieldRepositoryInterface  $fields
  * @param                           $id
  * @param                           $field
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function assign(AssignmentFormBuilder $form, TypeRepositoryInterface $types, FieldRepositoryInterface $fields, $id, $field)
 {
     $type = $types->find($id);
     return $form->setActions(['save' => ['redirect' => 'admin/posts/types/fields/' . $id]])->setStream($type->getEntryStream())->setField($fields->find($field))->render();
 }
 /**
  * Handle the command.
  *
  * @param AssignmentRepositoryInterface $assignments
  * @param StreamRepositoryInterface     $streams
  * @param FieldRepositoryInterface      $fields
  */
 public function handle(AssignmentRepositoryInterface $assignments, StreamRepositoryInterface $streams, FieldRepositoryInterface $fields)
 {
     $assignments->cleanup();
     $streams->cleanup();
     $fields->cleanup();
 }
 /**
  * Create an assignment.
  *
  * @param AssignmentFormBuilder     $form
  * @param FolderRepositoryInterface $folders
  * @param FieldRepositoryInterface  $fields
  * @param                           $id
  * @param                           $field
  * @return mixed
  */
 public function assign(AssignmentFormBuilder $form, FolderRepositoryInterface $folders, FieldRepositoryInterface $fields, $id, $field)
 {
     /* @var FolderInterface $folder */
     $folder = $folders->find($id);
     return $form->setActions(['save' => ['redirect' => 'admin/files/folders/assignments/' . $id]])->setStream($folder->getEntryStream())->setField($fields->find($field))->render();
 }
 /**
  * Return the modal for choosing a field to assign.
  *
  * @param FieldRepositoryInterface $fields
  * @return \Illuminate\View\View
  */
 public function chooseField(FieldRepositoryInterface $fields, TypeRepositoryInterface $types, $id)
 {
     $type = $types->find($id);
     return view('module::ajax/choose_field', ['fields' => $fields->findByNamespace('partials')->notAssignedTo($type->getEntryStream())->unlocked(), 'id' => $id]);
 }
 /**
  * Handle the command.
  *
  * @param MigrateAssignments $command
  */
 public function handle(MigrateAssignments $command)
 {
     $migration = $command->getMigration();
     $stream = $migration->getStream();
     $fields = $migration->getAssignments();
     $namespace = $migration->getNamespace();
     if (!$fields) {
         return;
     }
     $addon = $migration->getAddon();
     $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null)));
     foreach ($fields as $field => $assignment) {
         if (is_numeric($field)) {
             $field = $assignment;
             $assignment = [];
         }
         if (!is_array($assignment)) {
             throw new \Exception('The assignment must be an array or field_slug value.');
         }
         /**
          * If the label exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($label = array_pull($assignment, 'label')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.label', $label);
         }
         /**
          * If the label is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($assignment, config('app.fallback_locale') . '.label')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.label', $addon ? $addon->getNamespace("field.{$field}.label.{$stream->getSlug()}") : null);
         }
         /**
          * If the instructions exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($instructions = array_pull($assignment, 'instructions')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.instructions', $instructions);
         }
         /**
          * If the instructions is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($assignment, config('app.fallback_locale') . '.instructions')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.instructions', $addon ? $addon->getNamespace("field.{$field}.instructions.{$stream->getSlug()}") : null);
         }
         /**
          * If the placeholder exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($placeholder = array_pull($assignment, 'placeholder')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.placeholder', $placeholder);
         }
         /**
          * If the placeholder is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($assignment, config('app.fallback_locale') . '.placeholder')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.placeholder', $addon ? $addon->getNamespace("field.{$field}.placeholder.{$stream->getSlug()}") : null);
         }
         /**
          * If the warning exists in the base array
          * then move it to the translated array
          * for the default locale.
          */
         if ($warning = array_pull($assignment, 'warning')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.warning', $warning);
         }
         /**
          * If the instructions is not set then make one
          * based on a standardized pattern.
          */
         if (!array_get($assignment, config('app.fallback_locale') . '.warning')) {
             $assignment = array_add($assignment, config('app.fallback_locale') . '.warning', $addon ? $addon->getNamespace("field.{$field}.warning.{$stream->getSlug()}") : null);
         }
         $field = $this->fields->findBySlugAndNamespace($field, $stream->getNamespace());
         if ($field) {
             $this->assignments->create(array_merge($assignment, compact('field', 'stream')));
         }
     }
 }
 public function assign(AssignmentFormBuilder $form, TypeRepositoryInterface $types, StreamRepositoryInterface $streams, FieldRepositoryInterface $fields, $id, $field)
 {
     $type = $types->find($id);
     return $form->setStream($type->getEntryStream())->setField($fields->find($field))->render();
 }