mutual_credit-5.0.x-dev/src/Entity/ViewBuilder/WalletViewBuilder.php

src/Entity/ViewBuilder/WalletViewBuilder.php
<?php

namespace Drupal\mcapi\Entity\ViewBuilder;

use Drupal\mcapi\Entity\Currency;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Url;

/**
 * Render controller for wallets.
 */
class WalletViewBuilder extends EntityViewBuilder {

  /**
   * {@inheritDoc}
   */
  public function buildComponents(&$build, array $entities, array $displays, $view_mode) {
    $display = $displays['mcapi_wallet'];
    $unused = (bool)\Drupal::config('mcapi.settings')->get('render_unused');
    foreach ($entities as $id => $wallet) {
      $show_currencies = Currency::loadMultiple(array_keys($wallet->getAllStats($unused)));
      if ($options = $display->getComponent('balance_bars')) {
        foreach ($show_currencies as $curr_id => $currency) {
          $build[$id]['balance_bars_'.$curr_id] = mcapi_wallet_view_balance_bars($wallet, $currency) + [
            '#title' => t('Given and received'),
            '#weight' => $options['weight'],
            '#theme_wrappers' => ['mcapi_wallet_component']
          ];
        }
      }
      if ($options = $display->getComponent('balance_viz')) {
        foreach ($show_currencies as $curr_id => $currency){
          $build[$id]['balance_viz'][$curr_id] = mcapi_wallet_view_balance_viz($wallet, $currency) + [
            '#title' => t('Balance'),
            '#weight' => $options['weight'],
            '#theme_wrappers' => ['mcapi_wallet_component']
          ];
        }
      }
      if ($options = $display->getComponent('balances')) {
        foreach ($show_currencies as $curr_id => $currency){
          $build[$id]['balances'][$curr_id] = mcapi_wallet_view_balance($wallet, $currency) + [
            '#title' => t('Balances'),
            '#weight' => $options['weight'],
            '#theme_wrappers' => ['mcapi_wallet_component']
          ];
        }
      }
      if ($options = $display->getComponent('stats')) {
        foreach ($show_currencies as $curr_id => $currency) {
          $build[$id]['stats_'. $curr_id] = mcapi_wallet_view_stats($wallet, $currency) + [
            '#title' => t('Summary stats'),
            '#weight' => $options['weight'],
            '#theme_wrappers' => ['mcapi_wallet_component']
          ];
        }
      }
      if ($options = $display->getComponent('histories')) {
        foreach ($show_currencies as $curr_id => $currency) {
          // @todo consider putting multiple lines on one chart
          $build[$id]['histories_'.$curr_id] = mcapi_wallet_view_balance_history($wallet, $currency, 300, 150) + [
            '#title' => t('Balance history'),
            '#weight' => $options['weight'],
            '#theme_wrappers' => ['mcapi_wallet_component']
          ];
        }
      }
      if ($view_mode <> 'full' and $view_mode <> 'default') {
        // Also see Drupal\mcapi\Plugin\Block\HeldWallets
        $build[$id]['links'] = mcapi_wallet_links($wallet);
      }
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc