Commit 6d86ebd6 authored by chr.fritsch's avatar chr.fritsch Committed by slashrsm

Issue #2908544 by chr.fritsch, huzooka, seanB, slashrsm: Support media module...

Issue #2908544 by chr.fritsch, huzooka, seanB, slashrsm: Support media module in the Drupal core (introduced in 8.4.x)
parent e8a96d02
......@@ -32,7 +32,7 @@ crop.type.*:
sequence:
type: crop_type.third_party.[%key]
media_entity.bundle.third_party.crop:
media.type.*.third_party.crop:
type: mapping
label: 'Crop settings'
mapping:
......
......@@ -7,6 +7,38 @@
use Drupal\crop\Entity\Crop;
/**
* Implements hook_requirements().
*/
function crop_requirements($phase) {
$requirements = [];
// This branch of Crop API shouldn't be used with core < 8.4.x or with
// media_entity 1.x enabled.
$incompatible = FALSE;
$drupal_version = explode('.', \Drupal::VERSION);
if ($drupal_version[1] < 4) {
$incompatible = TRUE;
}
elseif (\Drupal::moduleHandler()->moduleExists('media_entity')) {
$info = system_get_info('module', 'media_entity');
if (version_compare($info['version'], '8.x-2') < 0) {
$incompatible = TRUE;
}
}
if ($incompatible) {
$requirements['crop_media'] = [
'title' => t('Crop API'),
'value' => t('This branch of Crop API is not compatible with the version of Media Entity installed.'),
'description' => t('This branch of Crop API is not compatible with the version of Media Entity installed.'),
'severity' => REQUIREMENT_ERROR,
];
}
return $requirements;
}
/**
* Delete orphaned crop entities.
*/
......
......@@ -7,12 +7,12 @@
* Provides storage and API for image crops.
*/
use \Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\crop\Entity\Crop;
use Drupal\image\Entity\ImageStyle;
use \Drupal\media_entity\MediaBundleInterface;
use \Drupal\file\FileInterface;
use Drupal\media\MediaTypeInterface;
use Drupal\file\FileInterface;
/**
* Implements hook_theme().
......@@ -42,9 +42,9 @@ function template_preprocess_crop_crop_summary(&$variables) {
*
* Adds crop configuraiton fields to media bundle form.
*/
function crop_form_media_bundle_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\media_entity\MediaBundleInterface $bundle */
$bundle = $form['#entity'];
function crop_form_media_type_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\media\MediaTypeInterface $bundle */
$bundle = $form_state->getStorage()['type'];
$options = [];
$allowed_field_types = ['file', 'image'];
foreach (\Drupal::service('entity_field.manager')->getFieldDefinitions('media', $bundle->id()) as $field_name => $field) {
......@@ -53,7 +53,7 @@ function crop_form_media_bundle_form_alter(&$form, FormStateInterface $form_stat
}
}
$form['#entity_builders'][] = 'crop_media_bundle_form_builder';
$form['#entity_builders'][] = 'crop_media_type_form_builder';
$form['crop'] = [
'#type' => 'fieldset',
'#title' => t('Crop configuration'),
......@@ -87,9 +87,9 @@ function crop_form_media_bundle_form_alter(&$form, FormStateInterface $form_stat
*
* Adds third party settings to Media bundle config entity.
*
* @see crop_form_media_bundle_form_alter()
* @see crop_form_media_type_form_alter()
*/
function crop_media_bundle_form_builder($entity_type, MediaBundleInterface $bundle, &$form, FormStateInterface $form_state) {
function crop_media_type_form_builder($entity_type, MediaTypeInterface $bundle, &$form, FormStateInterface $form_state) {
$bundle->setThirdPartySetting('crop', 'image_field', $form_state->getValue('image_field'));
}
......
......@@ -5,4 +5,4 @@ package: Media
type: module
dependencies:
- crop
- media_entity
- drupal:media (>= 8.4)
......@@ -59,8 +59,8 @@ class MediaEntity extends EntityProviderBase implements ContainerFactoryPluginIn
* {@inheritdoc}
*/
public function uri(EntityInterface $entity) {
/** @var \Drupal\media_entity\MediaBundleInterface $bundle */
$bundle = $this->entityTypeManager->getStorage('media_bundle')->load($entity->bundle());
/** @var \Drupal\media\MediaTypeInterface $bundle */
$bundle = $this->entityTypeManager->getStorage('media_type')->load($entity->bundle());
$image_field = $bundle->getThirdPartySetting('crop', 'image_field');
if ($entity->{$image_field}->first()->isEmpty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment