Skip to content

Instantly share code, notes, and snippets.

@insaurabh
Created July 25, 2019 06:35
Show Gist options
  • Save insaurabh/f8d200b0e44f0c9b55485babc51082c5 to your computer and use it in GitHub Desktop.
Save insaurabh/f8d200b0e44f0c9b55485babc51082c5 to your computer and use it in GitHub Desktop.
#craftcms get field type in craftcms 3
<!-- In service file -->
public function getFieldType($fieldName='')
{
if ($fieldName === '') {
return null;
}
$fieldType = (new Query())
->select(['type'])
->from(['{{%fields}}'])
->where(['handle' => $fieldName])
->one();
return $fieldType;
}
<!-- Now call this function anywhere in your plugin -->
$fieldType = CraftAjaxinate::$plugin->craftAjaxinateService->getFieldType('handleName');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment