Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nelson-ph/808324afbfec7112ce359d2bdf67256d to your computer and use it in GitHub Desktop.

Select an option

Save nelson-ph/808324afbfec7112ce359d2bdf67256d to your computer and use it in GitHub Desktop.
Drupal 8 Media library edit - Support multiple cardinality
Index: media_library_edit.module
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- media_library_edit.module (date 1549024812000)
+++ media_library_edit.module (date 1549024812000)
@@ -89,5 +89,28 @@
}
}
}
+ else{
+ $settings = $context['widget']->getThirdPartySettings('media_library_edit');
+ if (isset($settings['show_edit']) && $settings['show_edit']) {
+ $media = $context['items']->first()->entity;
+ if ($media) {
+ $edit_template = $media->getEntityType()->getLinkTemplate('edit-form');
+ if ($edit_template) {
+ foreach(\Drupal\Core\Render\Element::children($element['selection']) as $media_element){
+ $edit_url = Url::fromUserInput(str_replace('{media}', $element['selection'][$media_element]['target_id']['#value'], $edit_template), ['attributes'=>['target'=>'_blank']]);
+ $element['selection'][$media_element]['media_edit'] = [
+ '#type' => 'link',
+ '#title' => t('Edit media item'),
+ '#url' => $edit_url,
+ '#attributes' => [
+ 'class' => 'button',
+ ],
+ '#theme_wrappers'=> ['container'=>['#attributes'=>['class'=>['action-links']]]],
+ ];
+ }
+ }
+ }
+ }
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment