Created
December 23, 2017 04:03
-
-
Save cyberlex404/e84d0b2c85d1b51d997b66f0e43b0314 to your computer and use it in GitHub Desktop.
How to create a new Selection Rule(Condition) for Panels in Drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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.'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment