Skip to content

Instantly share code, notes, and snippets.

@wsydney76
Created March 19, 2024 18:17
Show Gist options
  • Save wsydney76/6c6706bb40e696339fef38c366851126 to your computer and use it in GitHub Desktop.
Save wsydney76/6c6706bb40e696339fef38c366851126 to your computer and use it in GitHub Desktop.
Get fields in Craft CMS 5 with identical settings
<?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