foldershare-8.x-1.2/src/Entity/FolderShareTraits/GetSetKindTrait.php
src/Entity/FolderShareTraits/GetSetKindTrait.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | <?php namespace Drupal\foldershare\Entity\FolderShareTraits; /** * Get/set FolderShare entity kind field. * * This trait includes get methods for FolderShare entity kind field, * along with utility functions to test for specific kinds of items. * * <B>Internal trait</B> * This trait is internal to the FolderShare module and used to define * features of the FolderShare entity class. It is a mechanism to group * functionality to improve code management. * * @ingroup foldershare */ trait GetSetKindTrait { /*--------------------------------------------------------------------- * * Kind field. * *---------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function getKind() { return $this ->get( 'kind' )->value; } /** * Sets the item kind. * * <B>This method is internal and strictly for use by the FolderShare * module itself.</B> * * The caller must call save() for the change to take effect. * * <B>Process locks</B> * This method does not lock access. The caller should lock around changes * to the entity. * * @param string $kind * The new kind. The value is not validated but is expected to * be one of the known kind names (e.g. FOLDER_KIND, FILE_KIND, * IMAGE_KIND, or MEDIA_KIND). * * @see ::getKind() * @see ::isFile() * @see ::isFolder() * @see ::isImage() * @see ::isMedia() */ private function setKind(string $kind ) { $this ->kind->setValue( $kind ); } /*--------------------------------------------------------------------- * * Test kind field. * *---------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function isFile() { return ( $this ->get( 'kind' )->value === self::FILE_KIND); } /** * {@inheritdoc} */ public function isFolder() { return ( $this ->get( 'kind' )->value === self::FOLDER_KIND); } /** * {@inheritdoc} */ public function isImage() { return ( $this ->get( 'kind' )->value === self::IMAGE_KIND); } /** * {@inheritdoc} */ public function isMedia() { return ( $this ->get( 'kind' )->value === self::MEDIA_KIND); } /*-------------------------------------------------------------------- * * Translations. * *-------------------------------------------------------------------*/ /** * Returns a translation of the entity kind in singular form. * * Standard entity kinds are mapped to their corresponding terms. * * @param string $kind * The kind of a FolderShare entity. * @param int $caseMode * (optional, default = MB_CASE_LOWER) The mix of case for the returned * value. One of MB_CASE_UPPER, MB_CASE_LOWER, or MB_CASE_TITLE. * * @return string * The user-visible term for the singular kind. * * @see ::translateKinds() */ public static function translateKind( string $kind , int $caseMode = MB_CASE_LOWER) { $term = '' ; switch ( $kind ) { case self::FILE_KIND: $term = t( 'file' ); break ; case self::IMAGE_KIND: $term = t( 'image' ); break ; case self::MEDIA_KIND: $term = t( 'media' ); break ; case self::FOLDER_KIND: $term = t( 'folder' ); break ; case 'rootlist' : $term = t( 'top-level items' ); break ; default : case 'item' : case 'items' : $term = t( 'item' ); break ; } return mb_convert_case( $term , $caseMode ); } /** * Returns a translation of the entity kind in plural form. * * Standard entity kinds are mapped to their corresponding terms. * * @param string $kind * The kind of a FolderShare entity. * @param int $caseMode * (optional, default = MB_CASE_LOWER) The mix of case for the returned * value. One of MB_CASE_UPPER, MB_CASE_LOWER, or MB_CASE_TITLE. * * @return string * The user-visible term for the plural kind. * * @see ::translateKind() */ public static function translateKinds( string $kind , int $caseMode = MB_CASE_LOWER) { $term = '' ; switch ( $kind ) { case self::FILE_KIND: $term = t( 'files' ); break ; case self::IMAGE_KIND: $term = t( 'images' ); break ; case self::MEDIA_KIND: $term = t( 'media' ); break ; case self::FOLDER_KIND: $term = t( 'folders' ); break ; case 'rootlist' : $term = t( 'top-level items' ); break ; default : case 'item' : case 'items' : $term = t( 'items' ); break ; } return mb_convert_case( $term , $caseMode ); } } |