Skip to content

Commit

Permalink
Create content context (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Eirik Stanghelle Morland <[email protected]>
  • Loading branch information
adamsokolowski06 and eiriksm authored Sep 18, 2024
1 parent bd78952 commit e9b76e8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ContentContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Frontkom\DrupalBehatDefinitions;

use Drupal\DrupalExtension\Context\RawDrupalContext;

/**
* Class ContentContext.
*
* Provide Behat step-definitions for content related operations.
*/
class ContentContext extends RawDrupalContext {

/**
* Unpublish the chosed term.
*
* @Then I unpublish term :name
*/
public function iUnpublishTerm($name) {
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
->loadByProperties(['name' => $name]);

if ($term) {
$term = reset($term);
$term->setUnpublished();
$term->save();
}
else {
throw new \Exception("Term with name '$name' not found");
}
}

}

0 comments on commit e9b76e8

Please sign in to comment.