# Custom Module Help

**URL:** <https://farmos.discourse.group/t/custom-module-help/1149>\
**Category:** Development\
**Tags:** support-request\
**Created:** [February 18, 2022, 12:41pm UTC](https://farmos.discourse.group/t/custom-module-help/1149 "2022-02-18T12:41:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [February 18, 2022, 12:41pm UTC](https://farmos.discourse.group/t/custom-module-help/1149/1 "2022-02-18T12:41:44Z")

</div>

Going to attempt to make a custom module,  
Initially I think I need some additional flags and data fields for Cattle.

I started with some flags, which seem to work but have generated warnings.

```auto
User warning: The configuration name "farm_flag.flag.bull" does not match the ID "flag_bull" in Drupal\Core\Config\ConfigInstaller->createConfiguration() (line 394 of core/lib/Drupal/Core/Config/ConfigInstaller.php).
Drupal\Core\Config\ConfigInstaller->createConfiguration('', Array) (Line: 152)
Drupal\Core\Config\ConfigInstaller->installDefaultConfig('module', 'farm_cattle_flags') (Line: 75)
Drupal\Core\ProxyClass\Config\ConfigInstaller->installDefaultConfig('module', 'farm_cattle_flags') (Line: 324)
Drupal\Core\Extension\ModuleInstaller->install(Array, 1) (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array) (Line: 476)
Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 592)
Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

```

Is there a naming convention for the ID’s? I’ve tried a few combinations of config name and ID including having them the same.

This is the current version:  
farm\_flag.flag.bull.yml

```auto
angcode: en
status: true
dependencies:
  enforced:
    module:
      - farm_cattle_flags
id: flag_bull
label: Stock Bull
entity_types: null

entity_types:
  asset:
    - animal

```

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [February 18, 2022, 12:53pm UTC](https://farmos.discourse.group/t/custom-module-help/1149/2 "2022-02-18T12:53:27Z")

</div>

@Farmer-Ed Change `id: flag_bull` to `id: bull` - the file name needs to match the `id` declared in YML. So if the file is named `farm_flag.flag.bull.yml` then the `id` should be `bull`. The pattern is `farm_flag.flag.[id].yml`.

---

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [February 18, 2022, 2:32pm UTC](https://farmos.discourse.group/t/custom-module-help/1149/3 "2022-02-18T14:32:51Z")

</div>

That fixed it alright, Thanks.

I was sure that was the combination I started with, but perhaps I used a capital letter.

---

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [February 19, 2022, 9:07am UTC](https://farmos.discourse.group/t/custom-module-help/1149/4 "2022-02-19T09:07:32Z")

</div>

Is there an easy way to add colour to tags? or does it require some additional PHP/CSS?

In case you don’t understand my accent, some color would do either 😃  
It’s not really a big issue as the additional tags already make searching for and organizing records much easier, but maybe being able to highlight a few would be good too.

---

<div class="post-metadata">

**Author:** ![mstenta](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/mstenta/32/4_2.png) [@mstenta](https://farmos.discourse.group/u/mstenta)\
**Post date:** [February 19, 2022, 3:16pm UTC](https://farmos.discourse.group/t/custom-module-help/1149/5 "2022-02-19T15:16:56Z")

</div>

> Is there an easy way to add colour to tags? or does it require some additional PHP/CSS?

You need to do PHP/CSS yourself. Nothing unified yet - but we have a tracking issue open for this!

> **[Unified flag styling mechanism](https://www.drupal.org/project/farm/issues/3244867)**
>
> Problem/Motivation farmOS 2.x only provides CSS for the three flags it provides (Monitor, Needs Review, and Priority). All other flags are given the default green style.

To style a flag named `myflag` you need three things:

1. A CSS file in your module (eg: [css/flag.css](https://github.com/farmOS/farmOS/blob/eb6f1043da00b7b21d122d3cba626c4d026371c3/modules/core/ui/theme/css/flag.css#L27))

```auto
.flag--myflag {
  background-color: #F00;
  border-color: #F00;
}

```

2. A libraries YML file (eg: [mymodule.libraries.yml](https://github.com/farmOS/farmOS/blob/eb6f1043da00b7b21d122d3cba626c4d026371c3/modules/core/ui/theme/farm_ui_theme.libraries.yml#L5)):

```auto
flag:
  css:
    theme:
      css/flag.css: { }

```

3. An implementation of `hook_preprocess_field__flag` that adds your CSS whenever flags are displayed on the page (eg: [mymodule.module](https://github.com/farmOS/farmOS/blob/eb6f1043da00b7b21d122d3cba626c4d026371c3/modules/core/ui/theme/farm_ui_theme.module#L60)):

```auto
/**
 * Implements hook_preprocess_HOOK().
 */
function mymodule_preprocess_field__flag(array &$variables) {
  $variables['#attached']['library'][] = 'mymodule/flag';
}

```

---

<div class="post-metadata">

**Author:** ![Farmer-Ed](https://yyz2.discourse-cdn.com/free1/user_avatar/farmos.discourse.group/farmer-ed/32/662_2.png) [@Farmer-Ed](https://farmos.discourse.group/u/Farmer-Ed)\
**Post date:** [February 19, 2022, 3:50pm UTC](https://farmos.discourse.group/t/custom-module-help/1149/6 "2022-02-19T15:50:12Z")

</div>

Ah nice!

I’ll give that a go, thanks.
