-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Afform - Rename blocks and joins for clarity
Renames the ambiguously named "block" and "join" afform properties, and changes the naming convention to "af{type}-title-munged".
- Loading branch information
Showing
31 changed files
with
532 additions
and
75 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
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
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
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
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
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,57 @@ | ||
<?php | ||
use CRM_Afform_ExtensionUtil as E; | ||
|
||
/** | ||
* Collection of upgrade steps. | ||
*/ | ||
class CRM_Afform_Upgrader extends CRM_Afform_Upgrader_Base { | ||
|
||
/** | ||
* Update names of blocks and joins | ||
* | ||
* @return TRUE on success | ||
* @throws Exception | ||
*/ | ||
public function upgrade_1000() { | ||
$this->ctx->log->info('Applying update 1000'); | ||
$scanner = new CRM_Afform_AfformScanner(); | ||
$localDir = $scanner->getSiteLocalPath(); | ||
|
||
// Update form markup with new block directive names | ||
$replacements = [ | ||
'afjoin-address-default>' => 'afblock-contact-address>', | ||
'afjoin-email-default>' => 'afblock-contact-email>', | ||
'afjoin-i-m-default>' => 'afblock-contact-i-m>', | ||
'afjoin-phone-default>' => 'afblock-contact-phone>', | ||
'afjoin-website-default>' => 'afblock-contact-website>', | ||
'afjoin-custom-' => 'afblock-custom-', | ||
]; | ||
foreach (glob("$localDir/*." . $scanner::LAYOUT_FILE) as $fileName) { | ||
$html = file_get_contents($fileName); | ||
$html = str_replace(array_keys($replacements), array_values($replacements), $html); | ||
file_put_contents($fileName, $html); | ||
} | ||
|
||
// Update form metadata with new block property names | ||
$replacements = [ | ||
'join' => 'join_entity', | ||
'block' => 'entity_type', | ||
]; | ||
foreach (glob("$localDir/*." . $scanner::METADATA_FILE) as $fileName) { | ||
$meta = json_decode(file_get_contents($fileName), TRUE); | ||
foreach ($replacements as $oldKey => $newKey) { | ||
if (isset($meta[$oldKey])) { | ||
$meta[$newKey] = $meta[$oldKey]; | ||
unset($meta[$oldKey]); | ||
} | ||
} | ||
if (!empty($meta['entity_type'])) { | ||
$meta['type'] = 'block'; | ||
} | ||
file_put_contents($fileName, json_encode($meta, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); | ||
} | ||
|
||
return TRUE; | ||
} | ||
|
||
} |
Oops, something went wrong.