-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from City-of-Helsinki/UHF-8705
UHF-8705: Structured data for Job listings
- Loading branch information
Showing
2 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
79 changes: 79 additions & 0 deletions
79
public/modules/custom/helfi_rekry_content/src/Entity/JobListing.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Drupal\helfi_rekry_content\Entity; | ||
|
||
use Drupal\node\Entity\Node; | ||
|
||
/** | ||
* Bundle class for hel_map paragraph. | ||
*/ | ||
class JobListing extends Node { | ||
|
||
/** | ||
* Get job description or override value. | ||
* | ||
* @return string | ||
* Job description. | ||
*/ | ||
public function getJobDescription() : string { | ||
return $this->get('field_job_description_override')->value ?: $this->get('job_description')->value; | ||
} | ||
|
||
/** | ||
* Get translated organization name if available or override value. | ||
* | ||
* @return string | ||
* Organization name. | ||
* | ||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException | ||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException | ||
* @throws \Drupal\Core\TypedData\Exception\MissingDataException | ||
*/ | ||
public function getOrganizationName() : string { | ||
if (!$this->get('field_organization_override')->first()) { | ||
return $this->get('field_organization_name')->value; | ||
} | ||
|
||
$storage = $this->entityTypeManager() | ||
->getStorage('taxonomy_term'); | ||
|
||
$organization_entity = $storage->load($this->get('field_organization_override')->first()->target_id); | ||
|
||
if (!$organization_entity->hasTranslation($this->get('langcode')->value)) { | ||
return $organization_entity->getName(); | ||
} | ||
|
||
$translated_organization_entity = $organization_entity->getTranslation($this->get('langcode')->value); | ||
return $translated_organization_entity->getName(); | ||
} | ||
|
||
/** | ||
* Get translated employment type if available. | ||
* | ||
* @return string | ||
* Employment type. | ||
* | ||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException | ||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException | ||
* @throws \Drupal\Core\TypedData\Exception\MissingDataException | ||
*/ | ||
public function getEmploymentType() : string { | ||
if (!$this->get('field_employment_type')->first()) { | ||
return ''; | ||
} | ||
|
||
$storage = $this->entityTypeManager() | ||
->getStorage('taxonomy_term'); | ||
|
||
$employment_type_entity = $storage->load($this->get('field_employment_type')->first()->target_id); | ||
|
||
if (!$employment_type_entity->hasTranslation($this->get('langcode')->value)) { | ||
return $employment_type_entity->getName(); | ||
} | ||
|
||
$translated_employment_type_entity = $employment_type_entity->getTranslation($this->get('langcode')->value); | ||
return $translated_employment_type_entity->getName(); | ||
|
||
} | ||
|
||
} |