You are here

class Helpers in Menu Multilingual 8

Various functions to assist menu_multilingual block.

Hierarchy

  • class \Drupal\menu_multilingual\Helpers

Expanded class hierarchy of Helpers

2 files declare their use of Helpers
MenuMultilingualBlockTrait.php in src/Plugin/Block/MenuMultilingualBlockTrait.php
menu_multilingual.module in ./menu_multilingual.module
Enhances the multilingual capabilities for the blocks with menus.

File

src/Helpers.php, line 11

Namespace

Drupal\menu_multilingual
View source
class Helpers {

  /**
   * Enable menu_multilingual block processing.
   */
  public static function setBlockProcessing(&$build) {
    $settings = $build['#configuration'];
    if (!empty($settings['only_translated_labels']) || !empty($settings['only_translated_content'])) {
      $modifier = \Drupal::service('menu_multilingual.modifier');
      $modifier
        ->filterLabels($settings['only_translated_labels']);
      $modifier
        ->filterContent($settings['only_translated_content']);
      $build['#pre_render'][] = [
        $modifier,
        'filterLinksInRenderArray',
      ];
    }
  }

  /**
   * Save menu_multilingual block settings.
   */
  public static function saveBlockSettings($entity_type, BlockInterface $block, &$form, FormStateInterface $form_state) {
    $settings = $form_state
      ->getValue([
      'settings',
      'multilingual',
    ]);
    $elements = $form['settings']['multilingual'];
    if ($elements['only_translated_labels']['#disabled']) {
      $settings['only_translated_labels'] = FALSE;
    }
    if ($elements['only_translated_content']['#disabled']) {
      $settings['only_translated_content'] = FALSE;
    }
    $block
      ->setThirdPartySetting('menu_multilingual', 'only_translated_labels', $settings['only_translated_labels']);
    $block
      ->setThirdPartySetting('menu_multilingual', 'only_translated_content', $settings['only_translated_content']);
  }

  /**
   * Check entity type for translation capabilities.
   */
  public static function checkEntityType($type) {

    /* @var \Drupal\content_translation\ContentTranslationManager $translationManager */
    $translationManager = \Drupal::service('content_translation.manager');
    return $translationManager
      ->isEnabled($type);
  }

  /**
   * Updater for the menu_multilingual block settings.
   */
  public static function languageContentSettingsSubmit() {

    // @todo: Add bulk change for block settings.
    // Use power of https://goo.gl/cm37vj
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Helpers::checkEntityType public static function Check entity type for translation capabilities.
Helpers::languageContentSettingsSubmit public static function Updater for the menu_multilingual block settings.
Helpers::saveBlockSettings public static function Save menu_multilingual block settings.
Helpers::setBlockProcessing public static function Enable menu_multilingual block processing.