[Week 7] Adding more functionality to media views and EB

Hello Drupalers!

You must have already read my introduction blog post about the media module for Drupal 8 on which I was working on with Janez Urevc (​slashrsm) and Tadej Baša (​paranojik) under Google Summer Of Code 2016.

Last week I wrote a blog post about the changes I made to the Media library views and entity browser.

Let me give you a brief introduction about what are entity browsers. Entity browser is a drupal module which provides a generic entity browser/picker/selector. One can easily add widgets such as views, entity forms or DropzoneJS file upload forms to an entity browser. You can see the demo of a entity browser in my GSoC mid term post.

The media module currently has two Entity browsers. One is for selecting and attaching media to various content types and the other one is for creating gallery. Entity browser for gallery is a super simple way to create gallery by choosing the media items. This week I did the following things:

1) Adding a bundle filter on media library views: The entity browser for gallery comes with two views. One for Global media library and the other one for User media library. I added bundle filters in both those views.

2) Adding a patch to remove Gallery option from bundle filters: A gallery can contain all kinds of media entities except Gallery type items. This is why I wrote a patch to remove the gallery option from the bundle filters in the views. Here is the URL to the PR.

3) Adding constraints for Gallery items: Applying the gallery filters in the views restricts the user to selecting media items except gallery type items. But one could still programmatically add gallery types of items in a gallery. I wrote constraints for Gallery bundle makes sure that there is not gallery type of item in a gallery. This is how the constraint validator looks like:

public function validate($value, Constraint $constraint) {
if (!isset($value)) {
return;
}
if ($value->hasField($constraint->sourceFieldName)) {
$slideshowItems = $value->get($constraint->sourceFieldName);
foreach ($slideshowItems as $item) {
if ($item->entity->getType()->getPluginId() == “slideshow”) {
$this->context->addViolation($constraint->message);
}
}
}
}

You can find this code in the src/Plugin/Validation/Constraint directory of the media module.

This week we’ll be adding more media bundles to the media module. I’ll post more updates next week. Stay tuned!

:)

 
3
Kudos
 
3
Kudos

Now read this

[Week 10] Fixing embedding issues and improving UI

Hello everyone! I have already mentioned in my introduction blog post about the media module for Drupal 8 on which I was working on with Janez Urevc (slashrsm) and Tadej Baša (paranojik) under Google Summer Of Code 2016. This week I... Continue →