0

Iam facing a strange task. I guess its not possible to solve it, but maybe one of you have an idea! :)

Default way for Responsive Images:

  • Create breakpoints.
  • Create an image style for each breakpoint.
  • Create a mapping, to link the breakpoints with image styles.
  • Load the mapping in "Manage Display".

The challenge:

  • Images are not directly uploaded to a node.
  • Instead, there is an extra content type, named "image". Those images will be referenced in the actually node.

Advantage: Images can be edited at one place, because they are used multiple times, sidewide.

Problem: Drupal doesnt know, where the image will be used later. Is it used in a list, article, slider? And each one of those wants different aspect ratios.

  1. Because of that, I can't set a mapping in the content type "image".
  2. The actual node (with the entity reference field) has no option to load mappings. I just can choose "Rendered Entity."

So - please tell me your thoughts. Is that stuff possible in Drupal 8? "Image Widget Crop" is used as well.

Thanks for your time, SuperEngineer 64

0

You can set the file usage manually. Example:

$entity_type = 'node';
$entity_id = 1;//Node ID
$fid = 1; // The file ID
$file = \Drupal\file\Entity\File::load($fid);
$file_usage = \Drupal::service('file.usage');
$file_usage->add($file, 'mymodule', $entity_type, $entity_id);

More details : http://www.drupal8.ovh/index.php/en/tutoriels/81/handle-file-drupal-8

0

I think that's pretty much sums up your task:

Media

Also there are other modules, that helps to extend media module functionality. I would go this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.