diff --git a/src/ContentLock/ContentLock.php b/src/ContentLock/ContentLock.php index 4dc6709..6a4938e 100644 --- a/src/ContentLock/ContentLock.php +++ b/src/ContentLock/ContentLock.php @@ -600,7 +600,7 @@ class ContentLock extends ServiceProviderBase { * it should be locked on entity level. */ public function isTranslationLockEnabled($entity_type_id) { - return in_array($entity_type_id, $this->configFactory->get('content_lock.settings')->get("types_translation_lock")); + return $this->moduleHandler->moduleExists('conflict') && in_array($entity_type_id, $this->configFactory->get('content_lock.settings')->get("types_translation_lock")); } } diff --git a/src/Form/ContentLockSettingsForm.php b/src/Form/ContentLockSettingsForm.php index ae2288c..2a07e50 100644 --- a/src/Form/ContentLockSettingsForm.php +++ b/src/Form/ContentLockSettingsForm.php @@ -3,9 +3,11 @@ namespace Drupal\content_lock\Form; use Drupal\Core\Entity\ContentEntityTypeInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityTypeManager; @@ -24,11 +26,19 @@ class ContentLockSettingsForm extends ConfigFormBase { protected $entityTypeManager; /** + * Drupal\Core\Extension\ModuleHandlerInterface module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * {@inheritdoc} */ - public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManager $entityTypeManager) { + public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManager $entityTypeManager, ModuleHandlerInterface $module_handler) { parent::__construct($config_factory); $this->entityTypeManager = $entityTypeManager; + $this->moduleHandler = $module_handler; } /** @@ -37,7 +47,8 @@ class ContentLockSettingsForm extends ConfigFormBase { public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('entity_type.manager') + $container->get('entity_type.manager'), + $container->get('module_handler') ); } @@ -115,6 +126,17 @@ class ContentLockSettingsForm extends ConfigFormBase { '#default_value' => in_array($definition->id(), $config->get('types_translation_lock')), '#description' => $this->t('Activating this options allows users to edit multiple translations concurrently') ]; + if (!$this->moduleHandler->moduleExists('conflict')) { + $form['entities'][$definition->id()]['translation_lock'] = [ + '#disabled' => TRUE, + '#default_value' => FALSE, + '#description' => $this->t('To allow editing multiple translations concurrently you need to install %module', + [ + '%module' => $this->getLinkGenerator()->generate('Conflict', Url::fromUri('https://www.drupal.org/project/conflict')) + ] + ), + ] + $form['entities'][$definition->id()]['translation_lock']; + } } }