"value":"\n <p>Today, I added a new feature to a project that allows a member to search for a node based on either its title or a specified field on that node, select a result from an autocomplete list and then be redirected to their selected node.<\/p>\n\n<p>I've already implemented this for other node types but needed to do the same for this node type.<\/p>\n\n<p>There are some differences, such as the node type to query for; the additional field depends on which node type as does the text shown in the autocomplete list.<\/p>\n\n<p>To do this, I needed to add a custom block and form, update the <code>AutocompleteController<\/code>, create a new instance of a <code>NodeQuery<\/code> class (a custom class within the custom module), register it as a service and update the <code>SearchQueryFactory<\/code> class.<\/p>\n\n<p>A principle that I follow as much as possible is the single responsibility principle, or SRP (the 'S' in SOLID), where each function or class only has one responsibility - such as returning a response for the autocomplete list, determining the correct node query to use based on the search being run or building the query itself - these are separated and split into their own files.<\/p>\n\n<p>Although more files and functions are created when coding in this way, though they are smaller and more straightforward to work with - which makes them easier to read, debug and maintain. It also makes code like the node query classes reusable as they aren't embedded within a larger class and are easier to test.<\/p>\n\n ",
"format":"full_html",
"processed":"\n <p>Today, I added a new feature to a project that allows a member to search for a node based on either its title or a specified field on that node, select a result from an autocomplete list and then be redirected to their selected node.<\/p>\n\n<p>I've already implemented this for other node types but needed to do the same for this node type.<\/p>\n\n<p>There are some differences, such as the node type to query for; the additional field depends on which node type as does the text shown in the autocomplete list.<\/p>\n\n<p>To do this, I needed to add a custom block and form, update the <code>AutocompleteController<\/code>, create a new instance of a <code>NodeQuery<\/code> class (a custom class within the custom module), register it as a service and update the <code>SearchQueryFactory<\/code> class.<\/p>\n\n<p>A principle that I follow as much as possible is the single responsibility principle, or SRP (the 'S' in SOLID), where each function or class only has one responsibility - such as returning a response for the autocomplete list, determining the correct node query to use based on the search being run or building the query itself - these are separated and split into their own files.<\/p>\n\n<p>Although more files and functions are created when coding in this way, though they are smaller and more straightforward to work with - which makes them easier to read, debug and maintain. It also makes code like the node query classes reusable as they aren't embedded within a larger class and are easier to test.<\/p>\n\n ",