You are here

class SocialGroupHero in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  2. 8.5 modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  3. 8.6 modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  4. 8.7 modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  5. 8.8 modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  6. 10.3.x modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  7. 10.0.x modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero
  8. 10.1.x modules/social_features/social_group/src/SocialGroupHero.php \Drupal\social_group\SocialGroupHero

Class SocialGroupHero.

@package Drupal\social_group

Hierarchy

Expanded class hierarchy of SocialGroupHero

1 string reference to 'SocialGroupHero'
social_group.services.yml in modules/social_features/social_group/social_group.services.yml
modules/social_features/social_group/social_group.services.yml
1 service uses SocialGroupHero
social_group.hero_image in modules/social_features/social_group/social_group.services.yml
Drupal\social_group\SocialGroupHero

File

modules/social_features/social_group/src/SocialGroupHero.php, line 12

Namespace

Drupal\social_group
View source
class SocialGroupHero {

  /**
   * Config Factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;
  protected $isSmall = FALSE;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactory $config_factory
   *   The injected configfactory.
   */
  public function __construct(ConfigFactory $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * Function that determines the group hero imagestyle.
   *
   * @return string
   *   Of the image / crop style.
   */
  public function getGroupHeroCropType() : string {
    $settings = $this->configFactory
      ->get('social_group.settings');

    // Return the selected style, or the default one.
    return $settings
      ->get('default_hero') ?? 'hero';
  }

  /**
   * Function that determines the group hero croptype.
   *
   * @return string
   *   The crop style.
   */
  public function getGroupHeroImageStyle() : string {
    return $this
      ->cropToStyle($this
      ->getGroupHeroCropType());
  }

  /**
   * Small or not.
   *
   * @return bool
   *   Is this considered small.
   */
  public function isSmall() : bool {

    // Invoke cropToStyle, to get info about the size.
    $this
      ->cropToStyle($this->configFactory
      ->get('social_group.settings')
      ->get('default_hero'));

    // Return info about the size.
    return $this->isSmall;
  }

  /**
   * Function that converts crop type to image style.
   *
   * @param string $cropType
   *   The croptype.
   *
   * @return string
   *   The associated image style.
   */
  protected function cropToStyle($cropType) : string {
    $values = [
      'hero' => 'social_xx_large',
      'hero_small' => 'social_hero_small',
    ];
    switch ($cropType) {
      case 'hero_small':
        $this->isSmall = TRUE;
      default:
    }
    return $values[$cropType] ?? 'social_xx_large';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialGroupHero::$configFactory protected property Config Factory.
SocialGroupHero::$isSmall protected property
SocialGroupHero::cropToStyle protected function Function that converts crop type to image style.
SocialGroupHero::getGroupHeroCropType public function Function that determines the group hero imagestyle.
SocialGroupHero::getGroupHeroImageStyle public function Function that determines the group hero croptype.
SocialGroupHero::isSmall public function Small or not.
SocialGroupHero::__construct public function Constructor.