コード例 #1
0
 /**
  * Handle the command.
  *
  * @param AssignmentSchema $schema
  */
 public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments)
 {
     $stream = $this->assignment->getStream();
     /* @var AssignmentInterface $assignment */
     $assignment = $assignments->find($this->assignment->getId());
     // If nothing is different then skip it.
     if ($assignment->isTranslatable() == $this->assignment->isTranslatable()) {
         return;
     }
     /*
      * If it's NOW translatable then move it from
      * the main table to the translations table.
      */
     if ($this->assignment->isTranslatable()) {
         $schema->dropColumn($stream->getEntryTableName(), $assignment->getFieldType(true));
         $schema->addColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true), $assignment);
     }
     /*
      * If it's NOT translatable then move it from
      * the translations table to the main table.
      */
     if (!$this->assignment->isTranslatable()) {
         $schema->dropColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true));
         $schema->addColumn($stream->getEntryTableName(), $assignment->getFieldType(true), $assignment);
     }
 }
コード例 #2
0
 /**
  * Handle the command.
  *
  * @param AssignmentRepositoryInterface $assignments
  */
 public function handle(AssignmentRepositoryInterface $assignments)
 {
     if ($this->builder->getFormOption('auto_assign') === true && $this->builder->getFormMode() === 'create') {
         $field = $this->builder->getFormEntry();
         $stream = $this->builder->getStream();
         $assignments->create(['stream_id' => $stream->getId(), 'field_id' => $field->getId()]);
     }
 }
コード例 #3
0
 /**
  * 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.');
 }
コード例 #4
0
 /**
  * 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')]);
 }
コード例 #5
0
    /**
     * 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')]);
    }
コード例 #6
0
 /**
  * Handle the command.
  *
  * @param AssignmentSchema              $schema
  * @param AssignmentRepositoryInterface $assignments
  */
 public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments)
 {
     $stream = $this->assignment->getStream();
     $type = $this->assignment->getFieldType(true);
     if (!$this->assignment->isTranslatable()) {
         $table = $stream->getEntryTableName();
     } else {
         $table = $stream->getEntryTranslationsTableName();
     }
     /* @var AssignmentInterface $assignment */
     $assignment = $assignments->find($this->assignment->getId());
     $assignment = clone $assignment;
     $schema->renameColumn($table, $type, $assignment);
 }
コード例 #7
0
 /**
  * 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);
         }
     }
 }
コード例 #8
0
 /**
  * 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();
 }
コード例 #9
0
 /**
  * Handle the command.
  *
  * @param AssignmentRepositoryInterface $assignments
  */
 public function handle(AssignmentRepositoryInterface $assignments)
 {
     foreach ($this->field->getAssignments() as $assignment) {
         $assignments->delete($assignment);
     }
 }
コード例 #10
0
 /**
  * Handle the command.
  *
  * @param  AssignmentRepositoryInterface $assignments
  * @return AssignmentInterface
  */
 public function handle(AssignmentRepositoryInterface $assignments)
 {
     return $assignments->create($this->stream, $this->field, $this->attributes);
 }
コード例 #11
0
 /**
  * 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();
 }
コード例 #12
0
 /**
  * Handle the command.
  *
  * @param AssignField $command
  * @return AssignmentInterface
  */
 public function handle(AssignField $command)
 {
     return $this->assignments->create($command->getStream(), $command->getField(), $command->getAttributes());
 }
コード例 #13
0
 /**
  * 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')));
         }
     }
 }
コード例 #14
0
 /**
  * Return a form to edit the field.
  *
  * @param AssignmentRepositoryInterface $assignments
  * @param FieldFormBuilder              $form
  * @param UserModel                     $model
  * @param                               $id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function edit(AssignmentRepositoryInterface $assignments, FieldFormBuilder $form, UserModel $model, $id)
 {
     /* @var AssignmentInterface $assignment */
     $assignment = $assignments->find($id);
     return $form->setStream($model->getStream())->render($assignment->getFieldId());
 }
コード例 #15
0
 /**
  * Handle the command.
  *
  * @param  UnassignField $command
  */
 public function handle(UnassignField $command)
 {
     if ($assignment = $this->assignments->findByStreamAndField($command->getStream(), $command->getField())) {
         $this->assignments->delete($assignment);
     }
 }