code: def layer_changed(self, layer):
          
          if not layer:
              enable_keyword_wizard = False
          elif not hasattr(layer, 'providerType'):
              enable_keyword_wizard = False
          elif layer.providerType() == 'wms':
              enable_keyword_wizard = False
          else:
              enable_keyword_wizard = True
  
          try:
              if layer:
                  if is_raster_layer(layer):
                      enable_field_mapping_tool = False
                  else:
                      keywords = KeywordIO().read_keywords(layer)
                      keywords_version = keywords.get('keyword_version')
                      if not keywords_version:
                          supported = False
                      else:
                          supported = (
                              is_keyword_version_supported(keywords_version))
                      if not supported:
                          enable_field_mapping_tool = False
                      else:
                          layer_purpose = keywords.get('layer_purpose')
  
                          if not layer_purpose:
                              enable_field_mapping_tool = False
                          else:
                              if layer_purpose == layer_purpose_exposure['key']:
                                  layer_subcategory = keywords.get('exposure')
                              elif layer_purpose == layer_purpose_hazard['key']:
                                  layer_subcategory = keywords.get('hazard')
                              else:
                                  layer_subcategory = None
                              field_groups = get_field_groups(
                                  layer_purpose, layer_subcategory)
                              if len(field_groups) == 0:
                                  # No field group, disable field mapping tool.
                                  enable_field_mapping_tool = False
                              else:
                                  enable_field_mapping_tool = True
              else:
                  enable_field_mapping_tool = False
          except (KeywordNotFoundError, NoKeywordsFoundError, MetadataReadError):
              # No keywords, disable field mapping tool.
              enable_field_mapping_tool = False
  
          self.action_keywords_wizard.setEnabled(enable_keyword_wizard)
          self.action_field_mapping.setEnabled(enable_field_mapping_tool)
docs: Enable or disable keywords editor icon when active layer changes.
  
          :param layer: The layer that is now active.
          :type layer: QgsMapLayer