-
Notifications
You must be signed in to change notification settings - Fork 4
CO-3003_Include_Terms_and_Conditions_and_backing_static_pages_in_People_provisioning_data #446
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,14 +29,53 @@ | |
|
|
||
| namespace App\Model\Entity; | ||
|
|
||
| use Cake\Core\Configure; | ||
| use Cake\ORM\Entity; | ||
| use Cake\ORM\TableRegistry; | ||
|
|
||
| class TermsAndConditions extends Entity { | ||
| use \App\Lib\Traits\EntityMetaTrait; | ||
|
|
||
| use \App\Lib\Traits\LabeledLogTrait; | ||
|
|
||
| protected array $_accessible = [ | ||
| '*' => true, | ||
| 'id' => false, | ||
| 'slug' => false, | ||
| ]; | ||
|
|
||
| /** | ||
| * Get the URL for this Terms and Conditions as a virtual field. | ||
Ioannis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * @param string|null $url Existing URL field value | ||
| * @return string|null URL | ||
| * @throws \Exception | ||
| * @since COmanage Registry v5.3.0 | ||
| */ | ||
| protected function _getUrl(?string $url = null): ?string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this call is on the entity rather than the table to facilitate the lookup in SqlProvisioner? Does the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, placing _getUrl() on the TermsAndConditions entity encapsulates the fallback logic directly on the data object, allowing $tc->url to resolve automatically across the entire codebase, including SqlProvisioner, TAndCAgreement, REST APIs, and templates, without requiring callers to instantiate or query a table helper.
Yes, because url is a physical database column, CakePHP tracks it in the entity's visible fields upon hydration from $SrcTable->find(), and $r->toArray() automatically invokes _getUrl(?string $url) during serialization to populate the resolved Mostly Static Page URL into the target record without needing the processTAndC callback. |
||
| if(!empty($url)) { | ||
| return $url; | ||
| } | ||
|
|
||
| if(!empty($this->mostly_static_page?->url)) { | ||
| return $this->mostly_static_page->url; | ||
| } | ||
|
|
||
| if(!empty($this->mostly_static_page_id)) { | ||
| try { | ||
| $MSPTable = TableRegistry::getTableLocator()->get('MostlyStaticPages'); | ||
| $msp = $MSPTable->get($this->mostly_static_page_id); | ||
| return $msp->url; | ||
| } catch(\Exception $e) { | ||
Ioannis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // We will rethrow here to facilitate debugging | ||
| if (Configure::read('debug')) { | ||
| throw $e; | ||
| } | ||
|
|
||
| $this->llog('error', $e->getMessage()); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.