X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_translation%2Fsrc%2FContentTranslationManager.php;h=e16cf168b8293c4246bec565132e73a3b55b32be;hb=9424afc6c1f518c301bf87a23c047d1873435d05;hp=da8bd1c618140077de9d7ad931f73a279e59cff4;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/content_translation/src/ContentTranslationManager.php b/web/core/modules/content_translation/src/ContentTranslationManager.php index da8bd1c61..e16cf168b 100644 --- a/web/core/modules/content_translation/src/ContentTranslationManager.php +++ b/web/core/modules/content_translation/src/ContentTranslationManager.php @@ -4,11 +4,12 @@ namespace Drupal\content_translation; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\workflows\Entity\Workflow; /** * Provides common functionality for content translation. */ -class ContentTranslationManager implements ContentTranslationManagerInterface { +class ContentTranslationManager implements ContentTranslationManagerInterface, BundleTranslationSettingsInterface { /** * The entity type manager. @@ -105,6 +106,23 @@ class ContentTranslationManager implements ContentTranslationManagerInterface { return $enabled; } + /** + * {@inheritdoc} + */ + public function setBundleTranslationSettings($entity_type_id, $bundle, array $settings) { + $config = $this->loadContentLanguageSettings($entity_type_id, $bundle); + $config->setThirdPartySetting('content_translation', 'bundle_settings', $settings) + ->save(); + } + + /** + * {@inheritdoc} + */ + public function getBundleTranslationSettings($entity_type_id, $bundle) { + $config = $this->loadContentLanguageSettings($entity_type_id, $bundle); + return $config->getThirdPartySetting('content_translation', 'bundle_settings', []); + } + /** * Loads a content language config entity based on the entity type and bundle. * @@ -128,4 +146,47 @@ class ContentTranslationManager implements ContentTranslationManagerInterface { return $config; } + /** + * Checks whether support for pending revisions should be enabled. + * + * @param string $entity_type_id + * The ID of the entity type to be checked. + * @param string $bundle_id + * (optional) The ID of the bundle to be checked. Defaults to none. + * + * @return bool + * TRUE if pending revisions should be enabled, FALSE otherwise. + * + * @internal + * There is ongoing discussion about how pending revisions should behave. + * The logic enabling pending revision support is likely to change once a + * decision is made. + * + * @see https://www.drupal.org/node/2940575 + */ + public static function isPendingRevisionSupportEnabled($entity_type_id, $bundle_id = NULL) { + if (!\Drupal::moduleHandler()->moduleExists('content_moderation')) { + return FALSE; + } + + foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) { + /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */ + $plugin = $workflow->getTypePlugin(); + $entity_type_ids = array_flip($plugin->getEntityTypes()); + if (isset($entity_type_ids[$entity_type_id])) { + if (!isset($bundle_id)) { + return TRUE; + } + else { + $bundle_ids = array_flip($plugin->getBundlesForEntityType($entity_type_id)); + if (isset($bundle_ids[$bundle_id])) { + return TRUE; + } + } + } + } + + return FALSE; + } + }