-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from johnkrovitch/bugfix/change-form-type
Bugfix/change form type
- Loading branch information
Showing
15 changed files
with
233 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export default class OptionsHelper { | ||
static initializeOptions(defaults, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
return Object.assign(defaults, options); | ||
} | ||
|
||
static getDOMElement(selector) { | ||
let element = document.querySelector(selector); | ||
|
||
if (!element) { | ||
throw new Error('No DOM Element with selector "' + selector + '" has been found'); | ||
} | ||
|
||
return element; | ||
} | ||
|
||
static getDOMNodeList(selector) { | ||
let elements = document.querySelectorAll(selector); | ||
|
||
if (!elements.length) { | ||
throw new Error('No DOM Element with selector "' + selector + '" has been found'); | ||
} | ||
|
||
return elements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import OptionsHelper from "../../helpers/OptionsHelper"; | ||
import MediaGallery from "../../gallery/MediaGallery"; | ||
|
||
export default class MediaEmbeddedForm { | ||
constructor(options) { | ||
this.options = OptionsHelper.initializeOptions({ | ||
selector: '.media-embed-form', | ||
}, options); | ||
this.element = OptionsHelper.getDOMElement(this.options.selector); | ||
} | ||
|
||
bind() { | ||
// Bind media radio buttons to display and hide form parts according to the selected value. | ||
let choices = this.element.querySelectorAll('.media-choice'); | ||
|
||
choices.forEach((choice) => { | ||
choice.addEventListener('change', (event) => { | ||
this.displayFormParts(event.target.value); | ||
}); | ||
}); | ||
} | ||
|
||
displayFormParts (value) { | ||
this | ||
.element | ||
.querySelectorAll('.media-choice-item') | ||
.forEach((element) => { | ||
if (element.dataset.src === value) { | ||
element.classList.remove('hidden'); | ||
|
||
if (value === 'choose_from_collection') { | ||
this.createMediaGallery(); | ||
} | ||
} else { | ||
element.classList.add('hidden'); | ||
} | ||
}) | ||
; | ||
} | ||
|
||
createMediaGallery() { | ||
this.gallery = new MediaGallery(); | ||
this.gallery.bind(); | ||
this.gallery.load(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# phpstan.neon | ||
parameters: | ||
excludes_analyse: | ||
- 'src/DependencyInjection/Configuration.php' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace JK\MediaBundle\Form\Type; | ||
|
||
use JK\MediaBundle\Validation\Constraints\UploadTypeConstraint; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\Extension\Core\Type\FileType; | ||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class MediaEmbedType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add('media', HiddenType::class, [ | ||
'attr' => [ | ||
'class' => 'cms-media-id-container', | ||
], | ||
]) | ||
->add('uploadType', ChoiceType::class, [ | ||
'choices' => MediaType::getUploadChoices(), | ||
'expanded' => true, | ||
'attr' => [ | ||
'class' => 'cms-media-choice', | ||
], | ||
]) | ||
->add('upload', FileType::class, [ | ||
'attr' => [ | ||
'class' => MediaType::UPLOAD_FROM_COMPUTER, | ||
], | ||
'label' => false, | ||
'help' => 'media.form.upload_help', | ||
'required' => false, | ||
]) | ||
->add('gallery', GalleryType::class) | ||
; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver | ||
->setDefaults([ | ||
'attr' => [ | ||
'class' => 'media-embed-form', | ||
], | ||
'constraints' => [ | ||
new UploadTypeConstraint(), | ||
], | ||
'label' => false, | ||
]) | ||
; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.