Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Lex
- * Date: 23.12.2017
- * Time: 6:52
- */
- namespace Drupal\housing\Plugin\Condition;
- use Drupal\Core\Condition\ConditionPluginBase;
- use Drupal\housing\Entity\HousingInterface;
- /**
- * Provides a 'Subscription Is Active' condition.
- *
- * @Condition(
- * id = "subscription_is_active",
- * label = @Translation("Subscription Is Active"),
- * category = @Translation("Housing"),
- * context = {
- * "housing" = @ContextDefinition("entity:housing",
- * label = @Translation("Housing")
- * )
- * }
- * )
- *
- */
- class SubscriptionIsActive extends ConditionPluginBase{
- /**
- * @inheritDoc
- */
- public function evaluate() {
- $pass = FALSE;
- /** @var \Drupal\housing\Entity\HousingInterface $housing */
- $housing = $this->getContextValue('housing');
- if (!$housing instanceof HousingInterface) {
- return $pass;
- }
- if(!$housing->getSubscription()) {
- return $pass;
- }
- $subscription = $housing->getSubscription();
- $pass = $subscription->isActive();
- return $pass;
- }
- /**
- * @inheritDoc
- */
- public function summary() {
- return $this->t('The TRUE if Subscription is active.');
- }
- }
Add Comment
Please, Sign In to add comment