Guest User

Untitled

a guest
Dec 27th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Lex
  5. * Date: 23.12.2017
  6. * Time: 6:52
  7. */
  8.  
  9. namespace Drupal\housing\Plugin\Condition;
  10.  
  11. use Drupal\Core\Condition\ConditionPluginBase;
  12. use Drupal\housing\Entity\HousingInterface;
  13.  
  14. /**
  15. * Provides a 'Subscription Is Active' condition.
  16. *
  17. * @Condition(
  18. * id = "subscription_is_active",
  19. * label = @Translation("Subscription Is Active"),
  20. * category = @Translation("Housing"),
  21. * context = {
  22. * "housing" = @ContextDefinition("entity:housing",
  23. * label = @Translation("Housing")
  24. * )
  25. * }
  26. * )
  27. *
  28. */
  29. class SubscriptionIsActive extends ConditionPluginBase{
  30.  
  31. /**
  32. * @inheritDoc
  33. */
  34. public function evaluate() {
  35. $pass = FALSE;
  36. /** @var \Drupal\housing\Entity\HousingInterface $housing */
  37. $housing = $this->getContextValue('housing');
  38. if (!$housing instanceof HousingInterface) {
  39. return $pass;
  40. }
  41.  
  42. if(!$housing->getSubscription()) {
  43. return $pass;
  44. }
  45.  
  46. $subscription = $housing->getSubscription();
  47. $pass = $subscription->isActive();
  48. return $pass;
  49. }
  50.  
  51. /**
  52. * @inheritDoc
  53. */
  54. public function summary() {
  55. return $this->t('The TRUE if Subscription is active.');
  56. }
  57.  
  58.  
  59. }
Add Comment
Please, Sign In to add comment