Taxonomy Terms More than one level and Clean Class throws error I am using clean_class and clean_id in twig. It was working with Parent Taxonomy Terms fine, but when I use Child Taxonomy Terms and try to render to Twig Template, I get this error message: 

Recoverable fatal error: Object of class Drupal\Core\Field\FieldItemList could not be converted to string in Drupal\Component\Utility\Html::getClass() (line 72 of **core\lib\Drupal\Component\Utility\Html.php).**

Drupal\Component\Utility\Html::getClass(Object) (Line: 259)
__TwigTemplate_4f47122ce7aa9a8c20dea186eff4ea8b5e46cc06c44f4f280e0f32c345504034-&gt;doDisplay(Array, Array) (Line: 455)
Twig\Template-&gt;displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template-&gt;display(Array) (Line: 434)
Twig\Template-&gt;render(Array) (Line: 64)
twig_render_template('themes/custom/cpv3/templates/page--node--community-plan-update--actualizacin-del-plan-comunitario-de-boyle-heights.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render('page', Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 501)
Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, 'html', NULL, 1) (Line: 109)
__TwigTemplate_0352d110804239c4a7412c9a9a76a1e3fccf9ff4943b7c48bf7ef5beaa137b28-&gt;doDisplay(Array, Array) (Line: 455)
Twig\Template-&gt;displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template-&gt;display(Array) (Line: 434)
Twig\Template-&gt;render(Array) (Line: 64)
twig_render_template('themes/custom/cpv3/templates/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager-&gt;render('html', Array) (Line: 437)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber-&gt;onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)


Line 72 in Html.php is the function regarding Clean Classes

* @param mixed $class
   *   The class name to clean. It can be a string or anything that can be cast
   *   to string.
   *
   * @return string
   *   The cleaned class name.
   */
  public static function getClass($class) {
    $class = (string) $class;
    if (!isset(static::$classes[$class])) {
      static::$classes[$class] = static::cleanCssIdentifier(mb_strtolower($class));
    }
    return static::$classes[$class];
  }


Is this a bug in Drupal Core or could it be my theme? How can I debug this?
The error message:


  Recoverable fatal error: Object of class
  Drupal\Core\Field\FieldItemList could not be converted to string


Unfortunately the field object FieldItemList can't be casted to a string, it doesn't have a magic __toString() method, but it does have a magic __get() method. So you can provide a property name, which is for most field types value, to get the field value as string:


  class FieldItemList
  
  Represents an entity field; that is, a list of field item objects.
  
  An entity field is a list of field items, each containing a set of
  properties. Note that even single-valued entity fields are represented
  as list of field items, however for easy access to the contained item
  the entity field delegates __get() and __set() calls directly to the
  first item.


Source: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21FieldItemList.php/class/FieldItemList/8.7.x