PluralTranslatableMarkup example

$migration_status = $executable->import();
      }
      catch (\Exception $e) {
        \Drupal::logger('migrate_drupal_ui')->error($e->getMessage());
        $migration_status = MigrationInterface::RESULT_FAILED;
      }

      switch ($migration_status) {
        case MigrationInterface::RESULT_COMPLETED:
          // Store the number processed in the sandbox.           $context['sandbox']['num_processed'] += static::$numProcessed;
          $message = new PluralTranslatableMarkup(
            $context['sandbox']['num_processed'], 'Upgraded @migration (processed 1 item total)', 'Upgraded @migration (processed @count items total)',
            ['@migration' => $migration_name]);
          $context['sandbox']['messages'][] = (string) $message;
          \Drupal::logger('migrate_drupal_ui')->notice($message);
          $context['sandbox']['num_processed'] = 0;
          $context['results']['successes']++;

          // If the completed migration has any follow-up migrations, add them           // to the batch migrations.           // @see onPostImport()           if (!empty(static::$followUpMigrations)) {
            
if (isset($counters[$severity['status']])) {
        $counters[$severity['status']]['amount']++;
      }
    }

    foreach ($counters as $key => $counter) {
      if ($counter['amount'] === 0) {
        continue;
      }

      $text = new PluralTranslatableMarkup($counter['amount']$counter['text']$counter['text_plural']);

      $element['#counters'][$key] = [
        '#theme' => 'status_report_counter',
        '#amount' => $counter['amount'],
        '#text' => $text,
        '#severity' => $key,
      ];
    }

    return $element;
  }

  

  public function testPluralTranslatableMarkupSerialization($count$expected_text) {
    // Add a mock string translation service to the container.     $container = new ContainerBuilder();
    $container->set('string_translation', $this->getStringTranslationStub());
    \Drupal::setContainer($container);

    // Create an object to serialize and unserialize.     $markup = new PluralTranslatableMarkup($count, 'singular @count', 'plural @count');
    $serialized_markup = unserialize(serialize($markup));
    $this->assertEquals($expected_text$serialized_markup->render());
  }

  /** * Data provider for ::testPluralTranslatableMarkupSerialization(). */
  public function providerPluralTranslatableMarkupSerialization() {
    return [
      [1, 'singular 1'],
      [2, 'plural 2'],
    ];
->willReturnCallback(function D$string, array $args = [], array $options = []) use ($translation) {
        return new TranslatableMarkup($string$args$options$translation);
      });
    $translation->expects($this->any())
      ->method('translateString')
      ->willReturnCallback(function DTranslatableMarkup $wrapper) {
        return $wrapper->getUntranslatedString();
      });
    $translation->expects($this->any())
      ->method('formatPlural')
      ->willReturnCallback(function D$count$singular$plural, array $args = [], array $options = []) use ($translation) {
        $wrapper = new PluralTranslatableMarkup($count$singular$plural$args$options$translation);
        return $wrapper;
      });
    return $translation;
  }

  /** * Sets up a container with a cache tags invalidator. * * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_validator * The cache tags invalidator. * * @return \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit\Framework\MockObject\MockObject * The container with the cache tags invalidator service. */

  protected function t($string, array $args = [], array $options = []) {
    return new TranslatableMarkup($string$args$options$this->getStringTranslation());
  }

  /** * Formats a string containing a count of items. * * @see \Drupal\Core\StringTranslation\TranslationInterface::formatPlural() */
  protected function formatPlural($count$singular$plural, array $args = [], array $options = []) {
    return new PluralTranslatableMarkup($count$singular$plural$args$options$this->getStringTranslation());
  }

  /** * Returns the number of plurals supported by a given language. * * @see \Drupal\locale\PluralFormulaInterface::getNumberOfPlurals() */
  protected function getNumberOfPlurals($langcode = NULL) {
    if (\Drupal::hasService('locale.plural.formula')) {
      return \Drupal::service('locale.plural.formula')->getNumberOfPlurals($langcode);
    }
    
'#attributes' => ['class' => ['form--inline', 'clearfix']],
    ];

    $bundles = $this->bundleInfoService->getAllBundleInfo();
    $existing_field_storage_options = $this->getExistingFieldStorageOptions();

    $rows = [];
    foreach ($existing_field_storage_options as $field) {
      $field_bundles = $field['field_storage']->getBundles();
      $summary = $this->fieldTypePluginManager->getStorageSettingsSummary($field['field_storage']);
      $cardinality = $field['field_storage']->getCardinality();
      $readable_cardinality = $cardinality === -1 ? $this->t('Unlimited') : new PluralTranslatableMarkup(1, 'Single value', 'Multiple values: @cardinality', ['@cardinality' => $cardinality]);

      // Remove empty values.       $list = array_filter([...$summary$readable_cardinality]);
      $settings_summary = [
        '#theme' => 'item_list',
        '#items' => $list,
        '#attributes' => [
          'class' => ['field-settings-summary-cell'],
        ],
      ];
      $bundle_label_arr = [];
      
/** * {@inheritdoc} */
  public function translateString(TranslatableMarkup $translated_string) {
    return $translated_string->getUntranslatedString();
  }

  /** * {@inheritdoc} */
  public function formatPlural($count$singular$plural, array $args = [], array $options = []) {
    return new PluralTranslatableMarkup($count$singular$plural$args$options$this);
  }

}
// Trigger "cron has not run recently" error:     $cron_config = \Drupal::config('system.cron');
    $time = \Drupal::time()->getRequestTime();
    \Drupal::state()->set('install_time', $time);
    $threshold_error = $cron_config->get('threshold.requirements_error');
    \Drupal::state()->set('system.cron_last', $time - $threshold_error - 1);

    $this->drupalGet('admin/reports/status');

    $error_elements = $this->cssSelect('.system-status-report__status-icon--error');
    $this->assertNotEquals(count($error_elements), 0, 'Errors are listed on the page.');
    $expected_text = new PluralTranslatableMarkup(count($error_elements), 'Error', 'Errors');
    $expected_text = count($error_elements) . ' ' . $expected_text;
    $this->assertSession()->responseContains((string) $expected_text);
  }

  /** * Tests that the Warning counter matches the displayed number of warnings. */
  public function testWarningElementCount() {
    // Trigger "cron has not run recently" with warning threshold:     $cron_config = \Drupal::config('system.cron');
    $time = \Drupal::time()->getRequestTime();
    
'langcode' => $this->defaultLangcode,
      'context' => '',
    ];
    $translation = $this->getStringTranslation($options['langcode']$string$options['context']);
    return $translation === FALSE ? $string : $translation;
  }

  /** * {@inheritdoc} */
  public function formatPlural($count$singular$plural, array $args = [], array $options = []) {
    return new PluralTranslatableMarkup($count$singular$plural$args$options$this);
  }

  /** * Sets the default langcode. * * @param string $langcode * A language code. */
  public function setDefaultLangcode($langcode) {
    $this->defaultLangcode = $langcode;
  }

  
Home | Imprint | This part of the site doesn't use cookies.