private function validateMemberAge() {
    /** @var \Drupal\node\Entity\Node $campaign Campaign node object. */
    $campaign = $this->getCampaign();
    /** @var \Drupal\openy_campaign\Entity\Member $member Temporary Member object. Will be saved by submit. */
    $member = $this->getMember();

    $minAge = $campaign->get('field_campaign_age_minimum')->value;
    $maxAge = $campaign->get('field_campaign_age_maximum')->value;

    $birthday = new \DateTime($member->getBirthDate());
    $now = new \DateTime();
    $interval = $now->diff($birthday)->format('%y');

    if (
      (!empty($minAge) && !empty($maxAge) && $interval >= $minAge &&  $interval <= $maxAge) ||
      (!empty($minAge) && empty($maxAge) && $interval >= $minAge) ||
      (empty($minAge) && !empty($maxAge) && $interval <= $maxAge)
    ) {
      return ['status' => TRUE, 'error' => ''];
    }

    return ['status' => FALSE, 'error' => t('Age is not between @min and @max.', ['@min' => $minAge, '@max' => $maxAge])->render()];

  }
private function validateMemberAge() {
    /** @var \Drupal\node\Entity\Node $campaign Campaign node object. */
    $campaign = $this->getCampaign();
    /** @var \Drupal\openy_campaign\Entity\Member $member Temporary Member object. Will be saved by submit. */
    $member = $this->getMember();

    $minAge = $campaign->get('field_campaign_age_minimum')->value;
    $maxAge = $campaign->get('field_campaign_age_maximum')->value;

    $birthday = new \DateTime($member->getBirthDate());
    $now = new \DateTime();
    $interval = $now->diff($birthday)->format('%y');

    if (
      (!empty($minAge) && !empty($maxAge) && $interval >= $minAge &&  $interval <= $maxAge) ||
      (!empty($minAge) && empty($maxAge) && $interval >= $minAge) ||
      (empty($minAge) && !empty($maxAge) && $interval <= $maxAge)
    ) {
      return ['status' => TRUE, 'error' => ''];
    }

    return ['status' => FALSE, 'error' => t('Age is not between @min and @max.', ['@min' => $minAge, '@max' => $maxAge])->render()];

  }
private function validateMemberAge ( ) { /** @var \Drupal\node\Entity\Node $campaign Campaign node object. */ $ campaign = $ this -> getCampaign ( ) ; /** @var \Drupal\openy_campaign\Entity\Member $member Temporary Member object. Will be saved by submit. */ $ member = $ this -> getMember ( ) ; $ minAge = $ campaign -> get ( 'field_campaign_age_minimum' ) -> value ; $ maxAge = $ campaign -> get ( 'field_campaign_age_maximum' ) -> value ; $ birthday = new \ DateTime ( $ member -> getBirthDate ( ) ) ; $ now = new \ DateTime ( ) ; $ interval = $ now -> diff ( $ birthday ) -> format ( '%y' ) ; if ( ( ! empty ( $ minAge ) && ! empty ( $ maxAge ) && $ interval >= $ minAge && $ interval <= $ maxAge ) || ( ! empty ( $ minAge ) && empty ( $ maxAge ) && $ interval >= $ minAge ) || ( empty ( $ minAge ) && ! empty ( $ maxAge ) && $ interval <= $ maxAge ) ) { return [ 'status' => TRUE , 'error' => '' ] ; } return [ 'status' => FALSE , 'error' => t ( 'Age is not between @min and @max.' , [ '@min' => $ minAge , '@max' => $ maxAge ] ) -> render ( ) ] ; }
Check if the member age fit to the Campaign age range.

@return array Array with status and error message.
Check if the member age fit to the Campaign age range .