Created
March 19, 2024 18:17
-
-
Save wsydney76/6c6706bb40e696339fef38c366851126 to your computer and use it in GitHub Desktop.
Get fields in Craft CMS 5 with identical settings
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
<?php | |
// .... | |
public function actionConsolidateFieldsCandidates() | |
{ | |
$signatures = []; | |
foreach (Craft::$app->getFields()->getAllFields() as $field) { | |
$signature = [ | |
'type' => get_class($field), | |
'translationMethod' => $field->translationMethod, | |
'translationKeyFormat' => $field->translationKeyFormat, | |
'searchable' => $field->searchable, | |
'settings' => $field->settings, | |
]; | |
$hash = md5(json_encode($signature)); | |
$signatures[$hash][] = $field->handle; | |
} | |
foreach ($signatures as $hash => $handles) { | |
if (count($handles) > 1) { | |
Console::output( implode(', ', $handles)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment