Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Issue #2830050 by bkosborne: FileUpload widget should allow file exte… #227

Merged
merged 2 commits into from
Dec 2, 2016

Conversation

bkosborne
Copy link
Contributor

This is to resolve this issue: https://www.drupal.org/node/2830050

This modified the BundleResolverInterface to expose the getPossibleBundles() method. I also refactored things a bit to make better use of the SourceFieldTrait. Not sure how comfortable you are with the API change. It seems like it would have little effect unless other users of Lightning decided to create their own bundle resolvers w/o extending the abstract one this module provides.

As for testing, I'm unable to get any of the behat tests that require JS to run on my Mac unfortunately (I installed JDK, selenium standalone server, and the chromium driver, but I still get failure to connect errors when a javascript test tries to run =/)

* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $fieldStorage;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is provided by the SourceFieldTrait, no longer needed

$plugin_definition = $this->getPluginDefinition();

$filter = function (MediaBundleInterface $bundle) use ($plugin_definition) {
$field = $this->getSourceField($bundle);
$field = $this->getSourceFieldForBundle($bundle);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this new method to the SourceFieldTrait and removed the locally defined method getSourceField below

@balsama
Copy link
Contributor

balsama commented Nov 28, 2016

This looks good to me. I'll give @phenaproxima a chance to look at it later in the week before merging since you said you have a workaround. Good catch.

@@ -13,6 +13,8 @@
*/
abstract class BundleResolverBase extends PluginBase implements BundleResolverInterface, ContainerFactoryPluginInterface {

use SourceFieldTrait;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about SourceFieldTrait being part of BundleResolverBase. It probably won't harm anything, but it isn't architecturally "pure", since the bundle resolver API shouldn't make assumptions about the media bundles in question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't it essentially already part of BundleResolverBase though? It had a method getSourceField which I removed in favor of using the trait since it was mostly code duplication.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. That's what I'm seeing too. Not sure how it got so hashed up.

* @return MediaBundleInterface[]
* Applicable media bundles, keyed by ID.
*/
public function getPossibleBundles();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a base implementation of this method in BundleResolverBase which simply returns all bundles, unconditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BundleResolverBase already has an implementation of this which I mostly kept untouched. Instead of returning all possible bundles it limits the bundles to those that have a matching source field definition.

*/
protected function getSourceFieldForBundle(MediaBundleInterface $bundle) {
$type_config = $bundle->getType()->getConfiguration();
if (!isset($type_config['source_field'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to if (empty()) so we can account for any falsy value.

* The configurable source field entity.
*/
protected function getSourceFieldForBundle(MediaBundleInterface $bundle) {
$type_config = $bundle->getType()->getConfiguration();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To re-use this code, let's change getSourceField() to:

return $this->getSourceFieldForBundle($entity->bundle->entity)

@phenaproxima
Copy link
Collaborator

This is looking great. I have a couple of fairly minor requests, then I think this can be merged.

…dle any falsey value for the source field name in SourceFieldTrait.
@phenaproxima phenaproxima merged commit 1ea2fde into acquia:8.x-1.x Dec 2, 2016
phenaproxima pushed a commit that referenced this pull request Dec 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants