How to identify a paragraph? Is there a way to identify a paragraph in Drupal 8. Like is there a function to get the type as paragraph in code level?

I need to get it from a form alter function. My requirement is to get all the paragraphs in a form. Or identify the paragraph fields.
You probably should look at the paragraphs module code, it does a lot of this.

That said, the basic process would probably be:


Identify the form fields that are entity_reference_revision fields.
Check that the field is limited to paragraph types (can just check
1st one).
If it is an update form, get the referenced entities from the field.
You will then need some recursive code to walk the paragraph tree to
get sub paragraphs.


This will require using a lot of the field definition classes to get the information needed.